简体   繁体   English

下拉菜单栏的CSS z-index属性

[英]CSS z-index property for a drop down menu bar

I have a drop down menu bar. 我有一个下拉菜单栏。 But it is always behind my content no matter how high I set the z-index of the bar or if I set the z-index of my content to -1. 但无论我设置条形的z-index多高,或者我将内容的z-index设置为-1,它总是落后于我的内容。 Can anybody help? 有人可以帮忙吗?

I did set the z-index to 500 where I do the hover of my navigation top menu but no change. 我确实将z-index设置为500,我将导航顶部菜单悬停,但没有变化。 Could it be because of the reset code I use in the beginning of my CSS code? 可能是因为我在CSS代码开头使用的重置代码?

Here is my CSS Code: 这是我的CSS代码:

/*navigation.xhtml; author: Mica */
#navigation {
    float:left;
    width:100%;
    height:18px;    
    margin:15px 0 25px;
}
#navigation ul {
    list-style-type:none;
    list-style-image:none;
    padding:0px;
    float:left;
    width: 100%;
}
#navigation li.topmenu {
    float:left;
    width:170px;
}
.topmenu a {
    float:left;
    width:100%;
    text-align:center;
}
.topmenu ul {
    float:left;
    display:none;
    width:100%;
}
.topmenu a, .submenu a, .topmenu:hover .submenu a {
    padding:3px 0;
    border:1px solid #C27000;
    color:#FFFFFF;
    font-weight:bold;
    text-decoration:none;
    background-color:#FF8C00;
    margin:0;
    font-weight:bold;
}
.submenu a{
    width:100%;
    clear:both;
    postition:absolute;
}
#navigation a:hover, .topmenu.on a, .topmenu:hover a {
    background-color:#FFA500;
}
.topmenu:hover ul {
    display:block;
    z-index:500;
}
#logo a:hover {
    opacity:0.8;
}

/*content in basicTemplate.xhtml; author: Mica */
#content {
    float:left;
    min-height:200px;
    margin:0 7px;
}

HAHAAA found it! 哈哈找到了! z-index only works when a position is declared first: so I need to set in this block a position: z-index仅在首先声明位置时才起作用:所以我需要在这个块中设置一个位置:

.topmenu:hover ul {
    display:block;
    z-index:500;
}

Like here: 像这儿:

.topmenu:hover ul {
    display:block;
    position:relative;
    z-index:500;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM