z-index IE7、IE8、IE9 不起作用?
z-index
CSS 属性在 Internet Explorer 7、8 和 9 上不起作用。如何解决此问题?
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/
The z-index
CSS property doesn't work on Internet Explorer 7, 8 and 9. How can I workaround this problem?
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;
}
If you click on the label, the input doesn't focus
You can see what happens here: http://jsfiddle.net/YKFuZ/2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经更新了你的代码 - http://jsfiddle.net/YKFuZ/6/
IE无法正确渲染
z-index
。因此,将div
的位置设置为绝对位置。并且 IE 不支持:focus
伪选择器。每当涉及 IE 时我都会坚持使用 javascript。编辑:输入的父级设置为相对,而输入元素本身设置为绝对。在这种情况下,
Z-index
将无法正确呈现。I've updated your code a bit - http://jsfiddle.net/YKFuZ/6/
IE doesn't render
z-index
properly. So set yourdiv
's Position to absolute. And IE doesn't support the:focus
pseudo-selector. I would stick to javascript whenever IE is concerned.EDIT: The input's parent is set to relative whereas the input element itself is set to absolute.
Z-index
will not be properly rendered in such a case.