我应该对伪元素使用单冒号还是双冒号? [英] Should I use single or double colon notation for pseudo-elements?

查看:28
本文介绍了我应该对伪元素使用单冒号还是双冒号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于 IE7 和 IE8 不支持伪元素的双冒号表示法(例如 ::after::first-letter),并且由于现代浏览器支持单冒号表示法(例如 :after)以实现向后兼容性,我应该只使用单冒号表示法并且当 IE8 的市场份额下降到可以忽略不计的水平时返回并在我的代码库?或者我应该同时包含两者:

Since IE7 and IE8 don't support the double-colon notation for pseudo-elements (e.g. ::after or ::first-letter), and since modern browsers support the single-colon notation (e.g. :after) for backwards compatibility, should I use solely the single-colon notation and when IE8's market share drops to a negligible level go back and find/replace in my code base? Or should I include both:

.foo:after,
.foo::after { /*styles*/ }

如果我关心 IE8 用户(可怜的宝贝),单独使用 double 似乎很愚蠢.

Using double alone seems silly if I care about IE8 users (the poor dears).

推荐答案

不要不要同时使用这两个和逗号.符合 CSS 2.1(不支持 CSS3)的用户代理将忽略整个规则:

Do not use both combined with a comma. A CSS 2.1 compliant (not CSS3 capable) user agent will ignore the whole rule:

当用户代理无法解析选择器(即,它不是有效的 CSS 2.1)时,它也必须忽略选择器和以下声明块(如果有).

When a user agent cannot parse the selector (i.e., it is not valid CSS 2.1), it must ignore the selector and the following declaration block (if any) as well.

CSS 2.1 为选择器中的逗号 (,) 赋予了特殊含义.然而,由于不知道逗号在未来的 CSS 更新中是否会获得其他含义,因此如果选择器中的任何地方出现错误,则应该忽略整个语句,即使选择器的其余部分在 CSS 2.1 中看起来是合理的.

CSS 2.1 gives a special meaning to the comma (,) in selectors. However, since it is not known if the comma may acquire other meanings in future updates of CSS, the whole statement should be ignored if there is an error anywhere in the selector, even though the rest of the selector may look reasonable in CSS 2.1.

http://www.w3.org/TR/CSS2/syndata.html#rule-设置

你可以使用

.foo:after { /*styles*/ }
.foo::after { /*styles*/ }

另一方面,这比必要的更冗长;目前,您可以坚持使用单冒号表示法.

On the other hand this is more verbose than necessary; for now, you can stick with the one-colon notation.

这篇关于我应该对伪元素使用单冒号还是双冒号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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