当我试图在我的网站上放置此警报栏时,我发现它与我的菜单重叠。一些文章说 z-index 和 position:absolute 可以将一个元素放在另一个元素之上,但这在这种情况下不起作用。我想知道如何将警报栏放在菜单上。任何帮助表示赞赏。
这是一个 说明问题的小提琴。
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: -webkit-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%,
hsla(0,0%,0%,.05));
background-image: -moz-linear-gradient(135deg, transparent,
transparent 25%, hsla(0,0%,0%,.1) 25%,
hsla(0,0%,0%,.1) 50%, transparent 50%,
transparent 75%, hsla(0,0%,0%,.1) 75%,
hsla(0,0%,0%,.1));
background-image: -ms-linear-gradient(135deg, transparent,
transparent 25%, hsla(0,0%,0%,.1) 25%,
hsla(0,0%,0%,.1) 50%, transparent 50%,
transparent 75%, hsla(0,0%,0%,.1) 75%,
hsla(0,0%,0%,.1));
background-image: -o-linear-gradient(135deg, transparent,
transparent 25%, hsla(0,0%,0%,.1) 25%,
hsla(0,0%,0%,.1) 50%, transparent 50%,
transparent 75%, hsla(0,0%,0%,.1) 75%,
hsla(0,0%,0%,.1));
background-image: linear-gradient(135deg, transparent,
transparent 25%, hsla(0,0%,0%,.1) 25%,
hsla(0,0%,0%,.1) 50%, transparent 50%,
transparent 75%, hsla(0,0%,0%,.1) 75%,
hsla(0,0%,0%,.1));
background-size: 20px 20px;
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%;
-webkit-animation: alert 1s ease forwards;
-moz-animation: alert 1s ease forwards;
-ms-animation: alert 1s ease forwards;
-o-animation: alert 1s ease forwards;
animation: alert 1s ease forwards;
}
/* Animation */
@-webkit-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { top: 0; }
}
@-moz-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { top: 0; }
}
@-ms-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { top: 0; }
}
@-o-keyframes alert {
0% { opacity: 0; }
50% { opacity: 1; }
100% { top: 0; }
}
@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;
}
#cssmenu > ul { *display: inline-block; }
#cssmenu:after, #cssmenu ul:after {
content: '';
display: block;
clear: both;
}
#cssmenu a {
background: #333;
color: #CBCBCB;
padding: 0 20px;
}
#cssmenu ul { text-transform: uppercase; }
#cssmenu ul ul {
border-top: 4px solid #1b9bff;
text-transform: none;
min-width: 190px;
}
#cssmenu ul ul a {
background: #1b9bff;
color: #FFF;
border: 1px solid #0082e7;
border-top: 0 none;
line-height: 150%;
padding: 16px 20px;
}
#cssmenu ul ul ul { border-top: 0 none; }
#cssmenu ul ul li { position: relative }
#cssmenu > ul > li > a { line-height: 48px; }
#cssmenu ul ul li:first-child > a { border-top: 1px solid #0082e7; }
#cssmenu ul ul li:hover > a { background: #35a6ff; }
#cssmenu ul ul li:last-child > a {
border-radius: 0 0 3px 3px;
box-shadow: 0 1px 0 #1b9bff;
}
#cssmenu ul ul li:last-child:hover > a { border-radius: 0 0 0 3px; }
#cssmenu ul ul li.has-sub > a:after {
content: '+';
position: absolute;
top: 50%;
right: 15px;
margin-top: -8px;
}
#cssmenu ul li:hover > a, #cssmenu ul li.active > a {
background: #1b9bff;
color: #FFF;
}
#cssmenu ul li.has-sub > a:after {
content: '+';
margin-left: 5px;
}
#cssmenu ul li.last ul {
left: auto;
right: 0;
}
#cssmenu ul li.last ul ul {
left: auto;
right: 99.5%;
}
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>