透明背景元素上的 IE z-index 问题
每个人。 我需要 2 个绝对定位的文本区域元素一个一个地放置。 这是我的示例:
<div>
<textarea id="txt1" style="position:absolute; top:0; left:0;z-index:0;background:none;">some text</textarea>
<textarea id="txt2" style="position:absolute; top:0; left:0;z-index:1;background:none;"></textarea>
</div>
我希望 txt1 位于 txt2 之下。 FF 和 Chrome 中就会出现这种情况。但在 IE 中(在 8 和 9 中测试)txt1 是可点击的并成为焦点。
有谁知道,如何管理这个?
提前致谢!
everyone.
I need 2 absolutely positioned textarea elements to be placed one over the other.
Here is my sample:
<div>
<textarea id="txt1" style="position:absolute; top:0; left:0;z-index:0;background:none;">some text</textarea>
<textarea id="txt2" style="position:absolute; top:0; left:0;z-index:1;background:none;"></textarea>
</div>
I'm expecting txt1 to be under the txt2. That happens in FF and Chrome. But in IE (tested in 8 and 9) txt1 is clickable and becomes focus.
Does anybody know, how to manage this?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Internet Explorer 不能很好地处理“空”元素。通过设置
background: none
并且没有任何内容,IE 会将顶部textarea
视为不存在。为了解决这个问题,您可以使用透明的 png 作为背景:
JSFiddle: http://jsfiddle。 net/j8Gkd/
编辑
按照@Ryan的建议,您可以使用数据URI将透明gif添加到背景,这意味着您不需要创建实际的透明png:
另一种解决方案,如建议的在这个答案中,是添加完全不透明的彩色背景:
Internet Explorer does not play well with "empty" elements. By making the
background: none
and having no content, IE treats the toptextarea
as if it was not there.To get around this, you can use a transparent png for the background instead:
JSFiddle: http://jsfiddle.net/j8Gkd/
Edit
As suggested by @Ryan, you can use data URI to add a transaparent gif to the background, meaning you do not need to create an actual transparent png:
Another solution, as suggested in this answer, is to add a coloured background with full opacity:
这是一个非常有趣的错误,我以前从未遇到过。 IE 的行为就像顶部的块根本不存在一样,因为它没有以可见方式呈现。
让我觉得奇怪的是它在 FF / Webkit 中工作,因为
none
可以作为background-image
属性的设置。这在属性的速记版本中应该可以正常工作,但我认为它也应该将背景颜色设置为默认值(通常是白色)。无论如何,我想我在这一点上是错的。将background
或background-color
设置为transparent
并不能解决问题。这里有一个解决方法:不要指定
background: none
,而是使用background-color: rgba(255, 255, 255, 0)
。这会给你一个透明的背景。不幸的是,它仅适用于 IE9。That's a very interesting bug that I've never encountered before. IE acts like the block on top isn't even there since it's not rendered visibly.
It strikes me as odd that it works in FF / Webkit because
none
would be a setting for thebackground-image
property. That should work okay in the shorthand version of the property, but I think it should also leave thebackground-color
set to the default (usually white). In any case, I guess I'm wrong about this. And setting eitherbackground
orbackground-color
totransparent
doesn't fix the problem.Here's a little bit of a workaround: Rather than specifying
background: none
, usebackground-color: rgba(255, 255, 255, 0)
. That will give you a transparent background. Unfortunately, it only works in IE9.这个错误仍然存在于 IE11 中,模拟 ie 10。我所做的一个纯 css 解决方法是强制背景颜色并使用:
当然我忘记了 IE7。
This bug is still at IE11 emulating to ie 10. A pure css workaround I did was force a background-color and work with:
Of course I'm forgetting IE7.