When I attempted to add this alert bar to my website, I encountered an issue where it was being hidden behind my menu. Some sources suggest that using z-index and position:absolute can resolve this problem by positioning one element above the other, but this did not work in my case. I am seeking advice on how to place the alert bar over the menu. Any assistance would be greatly appreciated.
Here is a demo that showcases the problem.
CSS:
body {
padding: 0;
}
/* Alert Bar */
#alert {
position: relative;
}
#alert:hover:after {
background: hsla(0,0%,0%,.8);
border-radius: 3px;
color: #f6f6f6;
content: 'Click to dismiss';
font: bold 12px/30px sans-serif;
height: 30px;
left: 50%;
margin-left: -60px;
position: absolute;
text-align: center;
top: 50px;
width: 120px;
}
#alert:hover:before {
border-bottom: 10px solid hsla(0,0%,0%,.8);
border-left: 10px solid transparent;
border-right: 10px solid transparent;
content: '';
height: 0;
left: 50%;
margin-left: -10px;
position: absolute;
top: 40px;
width: 0;
}
#alert:target {
display: none;
}
.alert {
background-color: #c4453c;
background-image: linear-gradient(135deg, transparent, transparent 25%, hsla(0,0%,0%,.05) 25%, hsla(0,0%,0%,.05) 50%, transparent 50%,
transparent 75%,hsla(0,0%,0%,.05)
75%);
box-shadow: 0 5px 0 hsla(0,0%,0%,.1);
color: #f6f6f6;
display: block;
font: bold 16px/40px sans-serif;
height: 40px;
position: absolute;
text-align: center;
text-decoration: none;
top: -45px;
width: 100%;
animation: alert 1s ease forwards;
}
/* Animation */
@keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { top: 0; }
}
/* Menu */
#cssmenu {padding: 0; margin: 0; border: 0;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding: 0;}
#cssmenu ul {position: relative; z-index: 597;}
#cssmenu ul li {float: left; min-height: 1px; vertical-align: middle;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 599; cursor: default;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598;}
#cssmenu ul ul li {float: none;}
#cssmenu ul ul ul {top: 0; left: auto; right: -99.5%;}
#cssmenu ul li:hover > ul { visibility: visible;}
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0;}
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; line-height: 1em; text-decoration: none; }
#cssmenu {
background: #333;
border-bottom: 4px solid #1b9bff;
font-family: 'Oxygen Mono', Tahoma, Arial, sans-serif;
font-size: 12px;
}
HTML:
<div id="alert">
<a class="alert" href="#alert"> Alert Bar overlapped</a>
</div>
<div id='cssmenu'>
<ul>
<li class='has-sub '><a href="#">XXX</a>
<ul>
<li><a href="#">XXX</a></li>
<li><a href="#">XXX</a></li>
<li><a href="#">XXX</a></li>
<li><a href="#">XXX</a></li>
<li><a href="#">XXX</a></li>
</ul>
</li>
<li class='has-sub '><a href="#">XXX</a>
<ul>
<li><a href="#">XXX</a></li>
<li><a href="#" class="messages">XXX</a></li>
<li><a href="#">XXX</a></li>
<li><a href="#" class="documents">XXX</a>
<ul>
<li><a href="#" class="documents">XXX</a></li>
<li><a href="#" class="documents">XXX</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">XXX</a></li>
<li class='has-sub'><a href="#">XXX</a>
<ul>
<li><a href="#">XXX</a></li>
</ul>
</li>
<li><a href="#">XXX</a></li>
</ul>
</div>