Internet 7、8和9上的z-index CSS属性不工作。我如何解决这个问题?
HTML:
<div>
<input type="text">
<span>label</span>
</div>
CSS:
body{background:#ddd;}
div{
position:relative;
width:250px;
height:30px;
line-height:30px;
background:#fff;
border:1px solid #666;
z-index:0;
}
input{
background:none;
border:0;
position:absolute;
top:0px;
left:0px;
width:242px;
height:22px;
padding:4px;
z-index:2;
*line-height:30px; /* ie7 needs this */
line-height /*\**/: 30px\9; /* ie8 needs this */
}
span{
position:absolute;
top:0px;
left:4px;
z-index:1;
}
input:focus + span{
filter: alpha(opacity=50);
-khtml-opacity: 0.50;
-moz-opacity: 0.50;
opacity: 0.50;
}如果单击标签,输入就不会聚焦
你可以看到这里发生了什么:http://jsfiddle.net/YKFuZ/2/
发布于 2011-08-26 12:52:15
我更新了你的代码- http://jsfiddle.net/YKFuZ/6/
IE不能正确地渲染z-index。因此,将div的位置设置为绝对。IE不支持:focus伪选择器。每当涉及IE时,我都会坚持使用javascript。
编辑:输入的父元素被设置为相对的,而输入元素本身被设置为绝对的。在这种情况下,Z-index将不能正确地呈现。
https://stackoverflow.com/questions/7204825
复制相似问题