IE不着色:以前作为table-cell,为什么? [英] IE not coloring :before as table-cell, why?

查看:114
本文介绍了IE不着色:以前作为table-cell,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <!DOCTYPE html> 
< html>
< head>
< style>
div:before {
display:table-cell;
content:ABC;
color:red;
}
< / style>
< / head>
< body>
< div> 123< / div>
< / body>
< / html>

我希望这会渲染到像,但我获得



这是一个错误还是我做错了什么?

解决方案

这似乎是IE中的一个错误。如果你检查IE 11开发工具中的元素,你会看到:before 伪元素被抛出之前的所有声明(也例如 font 设置,如果你添加它们),但是 display content p>

为了避免这个错误,在这个简单的情况下,设置 display:block 就足够了。在更复杂的情况下,您可能需要更复杂的解决方法。


<!DOCTYPE html>
<html>
    <head>
        <style>
        div:before {
            display: table-cell;
            content: "ABC";
            color: red;
        }
        </style>
    </head>
    <body>
        <div>123</div>
    </body>
</html>

I'd expect this to render to something like , but I get instead, only when running on Internet Explorer (any version).

Is this a bug or I'm doing something wrong?

解决方案

This appears to be a bug in IE. If you inspect the element in IE 11 Developer Tools, you see all the declarations for the :before pseudo-element struck out (also e.g. font settings if you add them), but the display and content settings affect the rendering.

To circumvent this bug, it suffices in this simple case to set display: block as @BeatAlex suggests. In a more complicated situation, you probably need more complicated workarounds.

这篇关于IE不着色:以前作为table-cell,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆