IE z-index trouble on element with transparent background

时间秒杀一切 提交于 2019-11-29 10:48:58
My Head Hurts

Internet Explorer does not play well with "empty" elements. By making the background: none and having no content, IE treats the top textarea as if it was not there.

To get around this, you can use a transparent png for the background instead:

background: url(/images/transparent.png) repeat scroll 0 0 transparent;

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:

background: transparent 0 0 repeat scroll url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBR‌​AA7"); 

Another solution, as suggested in this answer, is to add a coloured background with full opacity:

background:white; filter:alpha(opacity=1);

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 the background-image property. That should work okay in the shorthand version of the property, but I think it should also leave the background-color set to the default (usually white). In any case, I guess I'm wrong about this. And setting either background or background-color to transparent doesn't fix the problem.

Here's a little bit of a workaround: Rather than specifying background: none, use background-color: rgba(255, 255, 255, 0). That will give you a transparent background. Unfortunately, it only works in IE9.

This bug is still at IE11 emulating to ie 10. A pure css workaround I did was force a background-color and work with:

background-color: #000;
opacity: 0.0;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; //IE8 Support

Of course I'm forgetting IE7.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!