How to add a shadow under a navbar using CSS?
Asked Answered
M

3

8

I'm an absolute beginner when it comes to HTML & CSS> So, I reckon that this might sound easy to some of you.

I was looking for a way to add a simple shadow to the navbar, like the one on Codecademy's web to my pre-existing navbar. I'm including the HTML & CSS of it in this codepen

Mourning answered 14/3, 2020 at 7:26 Comment(0)
A
23

Add a box-shadow to your nav bar. not to site-header.

nav {
  box-shadow: 0 2px 4px 0 rgba(0,0,0,.2);
}
Aleece answered 14/3, 2020 at 7:44 Comment(1)
Tnx ! Can you explain what each element of that code does, technically ?Mourning
F
1

Just update your CSS file from this:

.site-header {
  box-shadow: 0 2px 4px 0 rgba(0,0,0,.1);
}

to this:

.site-header nav {
  box-shadow: 0 2px 4px 0 rgba(0,0,0,.2);
}

or

nav {
  box-shadow: 0 2px 4px 0 rgba(0,0,0,.2);
}
Frisette answered 14/3, 2020 at 7:37 Comment(1)
I just tried adding that code at the very end of the CSS file, and it unfortunately did not work :( .Mourning
C
0

In my case I needed

position: relative

on the navbar along with the box-shadow

Compressor answered 1/5 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.