user2997418 user2997418 - 2 months ago 9
CSS Question

CSS : button overlapped by a div,z-index not working

enter image description here

I have a top bar with a button and a navbar, for z-index reason I can only get the button working but the menu hided under the top bar or I get both but the button not clickable:

PS: I get this problem only on small display with the burger menu,
For the small device, Bootstrap uses this:

.navbar-fixed-top, .navbar-fixed-bottom {
position: fixed;
right: 0;
left: 0;
z-index: 1030;
}


If I override
Z-index:1030;
the bergur menu is hided under my headercss bar.

Here is my almost whole CSS, maybe some parts are not important for my problem:

HTML:

<div class="headercss navbar-fixed-top">
<div class="element"> <a class="btn btn-warning" href="www.test.com">Internet &gt;</a></div>
</div>

<div class="sidebar-nav">
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse sidebar-navbar-collapse" data-toggle="collapse" data-target=".navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="#">test</a></li>
<li><a href="#">test</a></li>
<li><a href="#">test</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>


CSS:

.headercss {
width: 100%;
height: 62px;
display:block;
overflow:auto;
background-color: #CAD722;
top: -1px;
left: 0px;
position: fixed;
z-index: 100;
}

}
.btn {
font-size: 18px;
font-weight: bold;
}


/* make sidebar nav vertical */
.navbar-default .navbar-nav>li>a {
font-weight: bold;
}

@media (min-width: 768px) {

.navbar-default{
width: 200px;;
height: 100%;
background-color: #e6dfd7;
z-index: 0;
}
.sidebar-nav .navbar .navbar-collapse {
margin-top: 65px;
padding: 0;
max-height: none;
}
.sidebar-nav .navbar ul {
float: none;
display: block;
}
.sidebar-nav .navbar li {
float: none;
display: block;
}
.sidebar-nav .navbar li a {
padding-top: 12px;
padding-bottom: 12px;
font-size: 16px;
}
.sidebar-nav .navbar li a:hover {
background-color: #CAD722;
}

}
/*fixing bootstrap*/
.col-sm-10 {
width: 100%;
float: right;
}

@media (min-width: 768px){
.col-sm-10 {
width: 85%;
}

}


.navbar-default .navbar-collapse,.navbar-default .navbar-form {
border-color:#CAD722;
}
.content{
position: relative;
}
.navbar-toggle {
margin-top: 11px;
margin-bottom: 1px;
margin-left: 5px;
float: left;
}

/*For small display*/
@media (max-width: 768px) {
.navbar-default {
background-color: transparent;
border-color: transparent;
}
.sidebar-nav .navbar li{
background-color: #CAD722;
}
}

Answer

The issue is that you essentially have two full-width navbars sitting on top of each other, with one button in each. Clearly, you'll only be able to click on the top one. One solution is to add width: 50%; to .navbar-default and width: 200%; to .navbar-collapse in the small display; This causes the navbar with the menu button to only cover half of the screen, allowing you to click on the Internet button, while the collapsible menu remains full-width.