CSS3 ::after继承IE9中origin元素的高度和边距吗?
我有这个 HTML:
<div class="demo">hello world</div>
和这个 CSS:
.demo { width: 100px;
height: 50px; margin-bottom: 50px;
background-color: red; position: relative;
z-index:-1;
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorStr=#40ffffff,EndColorStr=#12ffffff);zoom: 1;}
.demo::after {
width: 95px;
height: 95px;
position: absolute; left: 0; top: 0; border: 5px solid blue; content:"";
background-color: yellow; opacity: .75;}
我希望伪元素完全覆盖原始元素(其中包含 IE7,8 的 50% 渐变 - 因此高度:50%,边距底部:50%;)
但是在 IE9 中。 ..::after 元素仅覆盖 50%,尽管我特意将高度设置为 44px。这是因为使用了过滤器吗?知道如何覆盖它吗?
这是示例的 JSBin。
感谢您的帮助。
更新
这是整个事情的一个示例:
注意:
- 请参阅background.css 文件中的注释
- 我无法更改元素结构或将渐变分配给除.ui-icon 之外的任何其他元素
- 渐变应覆盖页脚的50%。页脚为 44px,因此渐变停止在 22px
- IE7+8 无法执行此操作(或颜色停止),因此我使用
- :: 在为位于 . ui-icon
问题 1 = IE9+ 渲染 ::before - 我使用 z-index:-1,因此 .ui-icon 位于 ::before = OK 后面
问题 2 = on IE9+ 的 ::before 背景被 .ui-icon 切断。
问题:如何避免 ::before 被切断之前的渐变?
I have this HTML:
<div class="demo">hello world</div>
and this CSS:
.demo { width: 100px;
height: 50px; margin-bottom: 50px;
background-color: red; position: relative;
z-index:-1;
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorStr=#40ffffff,EndColorStr=#12ffffff);zoom: 1;}
.demo::after {
width: 95px;
height: 95px;
position: absolute; left: 0; top: 0; border: 5px solid blue; content:"";
background-color: yellow; opacity: .75;}
I wanted the pseudo element to completely cover the origin element (which contains a 50% gradient for IE7,8 - therefore height: 50%, margin-bottom: 50%;)
However in IE9... the ::after element only covers 50%, although I specifically set the height to be 44px. Is this because of the use of filter? Any idea how to override it?
Here is a JSBin of the example.
Thanks for help.
UPDATE
Here is an example of the whole thing:
Notes:
- see comments in the background.css file
- I can't change the element structure or assign gradient to any other element than .ui-icon
- The gradient should cover 50% of the footer. Footer is 44px so gradient stops at 22px
- IE7+8 cannot do this (or color stops), so I making .ui-icon height 22px plus filter-gradient
- using ::before I add the gradient for all other browsers sitting on top of .ui-icon
Problem 1 = IE9+ renders ::before - I use z-index:-1, so .ui-icon sits behind ::before = OK
Problem 2 = on IE9+ the ::before background is cut off by .ui-icon.
Question: How can I avoid the gradient in ::before being cut off?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是因为
过滤器
。使用filter
会导致overflow:hidden
式的效果。您可能知道
:after
在元素内部呈现,如下所示:如果添加
overflow: hide
,则所有浏览器都会同样损坏:http://jsbin.com/otilux/3那么,如何修复它呢?一种选择是使用
::before
来处理具有filter
的绘制。参见: http://jsbin.com/otilux/4
这看起来是与之前在 Chrome/Firefox 中的情况相同,现在在 IE9 中也看起来相同。
由于使用
::after
而不是:after
,我可以看到您并没有尝试支持 IE8。因此,另一种选择是使用 SVG 渐变而不是过滤器
。Yes, it's because of the
filter
. Usingfilter
causes anoverflow:hidden
-esque effect.You might be aware that
:after
is rendered inside the element, like this:If you add
overflow: hidden
, then all browsers are equally broken: http://jsbin.com/otilux/3So, how to fix it? One option is to use
::before
to handle drawing the thing that hasfilter
.See: http://jsbin.com/otilux/4
That looks the same as it did before in Chrome/Firefox, and now also looks the same in IE9.
Due to using
::after
instead of:after
, I can see you're not trying to support IE8. So, another option would be to use an SVG gradient instead offilter
.