我应该使用单或双冒号表示法的伪元素吗? [英] Should I use single or double colon notation for pseudo-elements?

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

问题描述

由于IE7和IE8不支持伪元素的双冒号符号(例如 :: after :: first-letter ),并且由于现代浏览器支持单冒号表示法(例如:之后)以实现向后兼容性,因此我应该仅使用单冒号当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用户(不好的朋友),使用双人似乎很可笑。

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-sets

但您可以使用

.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天全站免登陆