Html 为什么 IE 11 不呈现 :after 元素,在开发工具中将 css 显示为划掉?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42076744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:21:42  来源:igfitidea点击:

Why is IE 11 not rendering :after element, showing css as crossed out in dev tools?

htmlcssinternet-explorerinternet-explorer-11ie11-developer-tools

提问by Edy Bourne

I have an angular app with two font icons in a given screen. These are rendered just fine in chrome, firefox and edge, but on IE 11 they do not display. The icons are to be rendered as the contentof the :afterpseudo class, which according to my research should work fine on IE 9 and up. However, on IE, these are simply not rendered.

我在给定的屏幕中有一个带有两个字体图标的 angular 应用程序。这些在 chrome、firefox 和 edge 中渲染得很好,但在 IE 11 上它们不显示。该图标将被呈现为content的的:after伪类,而根据我的研究,应该工作在IE 9和罚款。但是,在 IE 上,这些根本不会呈现。

As you can see in the screenshot, the :after element is not in the DOM displayed in the dev tools, and the css is correct but shows crossed out in dev tools:

正如您在屏幕截图中看到的,:after 元素不在开发工具中显示的 DOM 中,并且 css 是正确的,但在开发工具中显示为划掉:

IE 11 shows css for :after element crossed out, nothing is rendered

IE 11 显示 : 元素划掉后的 css,没有渲染任何内容

The relevant CSS that is compiled and actually used in the screen showing the issue is like so:

在显示问题的屏幕中编译并实际使用的相关 CSS 如下所示:

.profile-picture[_ngcontent-vem-9]:after {
    font-family: Material Icons;
    content: "\E3B0";
    font-size: 48px;
    top: 32px;
    left: 25px
}
.profile-picture[_ngcontent-vem-9] .title[_ngcontent-vem-9],
.profile-picture[_ngcontent-vem-9]:after {
    display: block;
    position: absolute;
    color: #9e9e9e;
    transition-duration: .3s
}

The rules above the crossed out ones are unrelated. But since someone asked to see them, here they are:

划掉的规则上面的规则是不相关的。但既然有人要求见他们,他们就在这里:

enter image description here

在此处输入图片说明

The question is: why is this happening, and how to fix it?

问题是:为什么会发生这种情况,以及如何解决?

回答by THawkins

I had a similar issue, the after element on an <a>tag wasn't rendered in IE11, though I could see the CSS style for it. Freddie's answer heresolved the issue for me. Add this to the css display: block;

我有一个类似的问题,<a>标签上的 after 元素没有在 IE11 中呈现,尽管我可以看到它的 CSS 样式。弗雷迪在这里的回答为我解决了这个问题。将此添加到cssdisplay: block;