IE9 是否支持 CSS3 ::before 和 ::after 伪元素?

发布于 2024-11-30 16:27:45 字数 374 浏览 4 评论 0原文

此 MS 兼容性表上,它说,IE9不支持伪元素 ::before::after,但当我尝试时似乎确实如此......参见 JSBin

我做错了什么吗?我认为 ::before::after 是向 IE9 隐藏内容的好工具,但事实上,它们不是。

On this MS compatibility table it says, IE9 does not support pseudo-elements ::before and ::after, but when I try it seems it does... see JSBin

Am I doing something wrong? I thought ::before and ::after would be nice tools to hide stuff from IE9, when in fact, they don't.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只为守护你 2024-12-07 16:27:45

CSS2 伪元素 :before:after 使用传统的单冒号表示法,由 IE8 及更高版本支持。他们对 CSS3 并不陌生。

另一方面,双冒号表示法是 CSS3 的新内容。 IE9 确实支持 ::before::after,同样适用于 CSS1 伪元素 ::first-line::first-letter。然而,今后,任何新的伪元素都不能使用单冒号语法,并且浏览器(包括 IE)预计将支持所有伪元素的双冒号语法。

我不知道为什么该表说 IE9 不支持新的伪元素语法,因为根据上面链接的各个选择器的文档以及您的测试用例,它确实支持新的伪元素语法。当然,还有这个答案。

The CSS2 pseudo-elements :before and :after, with the traditional single-colon notation, are supported by IE8 and later. They are not new to CSS3.

The double-colon notation, on the other hand, is new to CSS3. IE9 does support this new notation for ::before and ::after, and likewise for the CSS1 pseudo-elements ::first-line and ::first-letter. Going forward, however, no new pseudo-element may use the single colon syntax, and browsers (including IE) are expected to support the double colon syntax for all pseudo-elements.

I have no clue why that table says IE9 doesn't support the new pseudo-element syntax, because it certainly does according to the docs for the individual selectors linked above, and your test case. As well as, of course, this answer.

走过海棠暮 2024-12-07 16:27:45

IE 9 在“标准模式”下支持 ::after::before (带有两个冒号)符号。在“怪异模式”下,情况并非如此。可以按如下方式进行测试:

<style>
p::after  {  
  content: "***AFTER***";  
} 
</style>
<p>Hello world 

这里 CSS 规则被忽略,因为 IE 9 进入怪异模式。但是,如果您在一开始添加以下行,IE 9 就会进入标准模式,并且 CSS 规则生效:

<!doctype html>

在 IE 9 中, 怪异模式,不支持新的 CSS 功能(大多数既不在 CSS 2.1 中也不在 IE 旧版本中的功能)。在怪异模式下,IE 9 也不支持旧的单冒号符号 :after:before。它在“IE 8 模式”下支持它们(但不支持两个冒号版本),您可以在开发人员工具 (F12) 中手动选择、在“文档模式”菜单中或使用标签 < 在文档级别选择;meta http-equiv="X-UA-Compatible" content="IE=8">

IE 9 supports the notations ::after and ::before (with two colons) in “standards mode”. In “quirks mode”, it does not. This can be tested e.g. as follows:

<style>
p::after  {  
  content: "***AFTER***";  
} 
</style>
<p>Hello world 

Here the CSS rule is ignored, because IE 9 goes to quirks mode. But if you add the following line at the very start, IE 9 goes to standards mode and the CSS rule takes effect:

<!doctype html>

It is common in IE 9 that in quirks mode, new CSS features (most features that are neither in CSS 2.1 or in the IE legacy) are not supported. In quirks mode, IE 9 does not support the old one-colon notations :after and :before either. It supports them (but not the two-colon versions) in “IE 8 mode”, which you can select in developer tools (F12) manually, in the “document mode” menu, or at document level using the tag <meta http-equiv="X-UA-Compatible" content="IE=8">.

别想她 2024-12-07 16:27:45

引用自 http://www.w3.org/community/webed/wiki/Advanced_CSS_selectors< /a>

CSS3伪元素双冒号语法
请注意,新的 CSS3
编写伪元素的方法是使用双冒号,例如 a::after {
... },将它们与伪类区分开。你可能会看到这个
有时在 CSS 中。然而 CSS3 仍然允许使用单个冒号
伪元素,为了向后兼容,我们会
建议您暂时坚持使用此语法。

As quoted from http://www.w3.org/community/webed/wiki/Advanced_CSS_selectors

CSS3 pseudo-element double colon syntax
Please note that the new CSS3
way of writing pseudo-elements is to use a double colon, eg a::after {
... }, to set them apart from pseudo-classes. You may see this
sometimes in CSS. CSS3 however also still allows for single colon
pseudo-elements, for the sake of backwards compatibility, and we would
advise that you stick with this syntax for the time being.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文