z-index如何影响下拉菜单的格式?

时间:2012-06-27 11:21:11

标签: css drop-down-menu menu fonts z-index

想知道是否有人可以解释如何更改模板上div的z-index会影响我标题中下拉菜单的字体样式?如果我设置z-index使得div位于(重叠)菜单的前面,那么菜单格式保持不变。如果我设置z-index使div位于菜单后面,那么一些重叠但不是全部的菜单的字体会发生变化!!!我用Google搜索了但似乎没有引用z-index影响除堆叠顺序之外的任何内容。浏览器的结果是一样的。

这是代码:请注意,如果我将div设置为菜单下方的样式,即位置顶部:270px,则菜单会正确显示。

http://matchmybag.com/altered-menu-formatting.png
http://matchmybag.com/correct-menu-formating.png 
http://matchmybag.com/z-index-menu-behind-div.png

菜单代码

<div id="menu"><?php if ($categories) { ?>


<ul>
  <?php foreach ($categories as $category) { ?>
</li>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
  <?php if ($category['children']) { ?>
  <div>
    <?php for ($i = 0; $i < count($category['children']);) { ?>
    <ul>
      <?php $j = $i + ceil(count($category['children']) / $category['column']); ?>
      <?php for (; $i < $j; $i++) { ?>
      <?php if (isset($category['children'][$i])) { ?>
      <li><a href="<?php echo $category['children'][$i]['href']; ?>"><?php echo $category['children'][$i]['name']; ?></a></li>
      <?php } ?>
      <?php } ?>
    </ul>
    <?php } ?>
  </div>
  <?php } ?>
</li>
<?php } ?>

MENU CSS:

#menu {
    color:#162732;
    border-bottom: 1px solid #162732;
    height: 22px;
    margin-bottom: /*10px15px*/;
    top:90px;
    width:900px;
}
#menu ul {
    list-style: none;
    margin: 0;
    padding:0;
    width:900px;

}
#menu > ul > li {
    position: relative;
    float: left;
    z-index: 20;    

}

#menu > ul > li > a.first {
    font-size: 11px;
    color: #162732;
    line-height: 14px;
    text-decoration: none;
    display: block;
    padding: 5px 7px 5px 7px;
    margin: 0px 36px 0px 0px;
    z-index: 6;
    position: static;
    float:none;
}


#menu > ul > li > a.last {
    font-size: 11px;
    color: #162732;
    line-height: 14px;
    text-decoration: none;
    display: block;
    padding: 5px 7px 5px 7px;
    margin: 0px 0px 0px 2px;
    z-index: 6;
    position: static;
    float:none;
}

#menu > ul > li > a {
    font-size: 11px;
    color: #162732;
    line-height: 14px;
    text-decoration: none;
    display: block;
    margin: 0px 33px 0px 0px;
    padding:5px 7px 5px 7px;
    /*padding: 7px 40px 7px 40px;*/
    z-index: 6;
    position: static;
    float:none;
}

#menu > ul > li > a:hover {
    font-size: 11px;
    color: #FFF;
    background: #162732;
    line-height:13PX;
    margin-bottom:1px;
    /*line-height: 15px;
    text-decoration: none;
    display: block;
    padding: 12px 15px 11px 15px;
    z-index: 6;
    position: relative;*/
}

#menu > ul > li > div {
    display: none;
    background: #162732;
    font-size: 10PX;
    position: absolute;
    z-index: 5;
    padding: 7px;
    margin-left:0px;
    margin-top:-2px;
    /*border: 1px solid #000000;
    -webkit-border-radius: 0px 0px 5px 5px;
    -moz-border-radius: 0px 0px 5px 5px;
    -khtml-border-radius: 0px 0px 5px 5px;
    border-radius: 0px 0px 5px 5px;*/
    /* [disabled]background: url('../image/menu.png'); */
}
#menu > ul > li:hover > div {
    display: table;
}
#menu > ul > li > div > ul {
    display: table-cell;

}
#menu > ul > li ul + ul {
    /*padding-left: 20px;*/
}
#menu > ul > li ul > li > a {
    font-size: 10PX;
    text-decoration: none;
    padding-top: 5px;
    padding-bottom:5px;
    margin-left:0px;
    color: #FFFFFF;
    display: block;
    white-space: nowrap;
    min-width: 120px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    margin-left: 0px;
}
#menu > ul > li ul > li > a:hover {
    background: none;
    color:#FFFFFF;
}

#menu > ul > li > div > ul > li > a {
    color: #FFFFFF;

DIV CODE AND STYLING

<?php //BOF Product Attribute Pictures ?>
<div class="left" style=" background-color:transparent; width:600px; float:left; display:inline; position:absolute; top: 170px; z-index:4"><table><?php include_once('catalog/view/paps/includes/modules/paps.php'); ?></table></div>
<?php //EOF Product Attribute Pictures ?>
  </div>

0 个答案:

没有答案