好吧,所以我在容器里装了几个div。两个内部div重叠15px;问题是我无法按照自己的意愿对它们进行分层。
<div class="headerButtons">
<div id="WorkTableButton" class="WorkTableButtonActive">
Work Table
</div>
<div id="additionalCostsButton" class="additionalCostsButtonInactive">
Additional Costs
</div>
</div>
,CSS看起来像这样,
.headerButtons{
margin:auto;
text-align:center;
}
.headerButtons div{
text-align:center;
height:27px;
text-indent:-9999%;
display:inline-block;
cursor:pointer;
}
#WorkTableButton{
width: 195px;
}
.WorkTableButtonActive{
background: url(ui_images/WorkTableActiveButton.png) no-repeat;
z-index:99999;
}
#additionalCostsButton{
width: 192px;
position:relative;
left: -15px;
}
.additionalCostsButtonInactive{
background: url(ui_images/AdditionalCostsInnactiveButton.png) no-repeat;
z-index:0;
}
问题是,#workTableButton div仍然显示在#additionalCostsButton后面,即使WorkTableButtonActive类应用于它,div将div层叠在另一个上面......对吗?
我做错了什么?
答案 0 :(得分:2)
z-index
属性仅适用于已经明确定位的元素。
您需要为#WorkTableButton
添加一个位置,如下所示:
#WorkTableButton{
width: 195px;
position: relative;
}
在此之后,{p> #additionalCostsButton
会出现在#WorkTableButton
后面。
答案 1 :(得分:1)
更改
#additionalCostsButton {
left: -15px;
}
到
#additionalCostsButton {
margin-left: -15px;
}