css - 伪元素中的字体系列

标签 css internet-explorer pseudo-element css-tables

Internet Explorer 8、9、10 似乎始终使用相同的(系统)字体。事实上,Internet Explorer 根本不关心font-family。重要的是 display:table-cell:before:after 的组合:

<!DOCTYPE html>
<html>
<head>
    <style>

        body > div {
            display: table;
        }

        body > div > div:before {
            font-family: monospace;
            display: table-cell;
            content: 'Not a monospace font in IE.';
        }
    </style>
</head>
<body>
    <div>
        <div>
        </div>
    </div>
</body>
</html>

这是一个已知的错误吗?找不到任何相关内容。

最佳答案

http://jsfiddle.net/KnfaW/

在我看来,display: table-cell 导致了这个问题。

User agents must ignore the following properties with :before and :after pseudo-elements: 'position', 'float', list properties, and table properties.

The :before and :after pseudo-elements elements allow values of the 'display' property as follows:

If the subject of the selector is a block-level element, allowed values are 'none', 'inline', 'block', and 'marker'. If the value of the 'display' has any other value, the pseudo-element will behave as if the value were 'block'.
If the subject of the selector is an inline-level element, allowed values are 'none' and 'inline'. If the value of the 'display' has any other value, the pseudo-element will behave as if the value were 'inline'.

W3C CSS2

因此,不要使用 display: table-cell,而是使用 display: block。它将按预期工作。在我看来,在这种情况下 IE 的错误处理可能会出现错误。

关于css - 伪元素中的字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18019697/

相关文章:

css - 无法制作 flex-flow :row work

google-chrome - 为什么IE和Chrome显示的内容不一样?

javascript - Overlap::after 和::before 伪元素与托管文本元素

CSS 选择器和内容属性在两个内联 block 元素之间添加一个空格字符

css - BODY 背景图像在浏览器视口(viewport)中被截断

css - CSS 中的跨度问题

c# - 是否可以将背景位置添加到 img/asp :image tag

css - 当站点位于网络驱动器时,IE 无法正确呈现 CSS

javascript - 为什么此函数仅在 IE11 上需要分号?

css - 即 :11 hover on before not working