Reputation:
I want a non-transparent navbar. When I add position: fixed;
to my navbar I see that when I scroll that the navbar is transparent. How to avoid this?
GitHub Repo: https://github.com/CalogerN/Conquer
Live Preview: https://calogern.github.io/Conquer/ (under construction)
I tried opacity: 1
but it does nothing.
.navbar {
list-style: none;
margin-top: 0;
height: 78px;
font-size: 20px;
background-color: #383e4c;
text-align: center;
margin-bottom: 0px;
font-family: "Open Sans";
font-weight: 700;
position: fixed;
opacity: 1;
width: 100%;
}
<nav>
<ul class="navbar">
<li><button type="button" name="button" class="nav-
btn">Homepage</button></li>
<li><button type="button" name="button" class="nav-btn">About Us</button>
</li>
<li><button type="button" name="button" class="nav-btn">Services</button>
</li>
<li><button type="button" name="button" class="nav-btn">Contact</button>
</li>
<li><button type="button" name="button" class="nav-btn">External</button>
</li>
</ul>
</nav>
Upvotes: 0
Views: 112
Reputation: 834
So here there is nothing to do with transparency.
Your .navbar
has position: fixed;
.
Here you have the problem with vertical stacking order of elements that overlap.
You are having that problem because in your code you have a .hero
. The elements inside .hero
have position: relative;
.
You can just solve this problem by adding a z-index: 1;
to your .navbar
.
The z-index
property specifies the stack order of an element.
An element with greater stack order is always in front of an element with a lower stack order.
Note:
z-index
only works on positioned elements.
.navbar {
list-style: none;
margin-top: 0;
height: 78px;
font-size: 20px;
background-color: #383e4c;
text-align: center;
margin-bottom: 0px;
font-family: "Open Sans";
font-weight: 700;
position: fixed;
/* opacity: 1; */
z-index: 99;
width: 100%;
}
Read More about Z-Index MDN web docs
Upvotes: 0
Reputation: 3507
just simply add z-index:99
to your navbar !
.navbar {
list-style: none;
margin-top: 0;
height: 78px;
font-size: 20px;
background-color: #383e4c;
text-align: center;
margin-bottom: 0px;
font-family: "Open Sans";
font-weight: 700;
position: fixed;
/* opacity: 1; */
z-index: 99;
width: 100%;
}
Upvotes: 2
Reputation: 194
Upvotes: 0