为什么这里有两个冒号

为什么这里有两个冒号

本文介绍了为什么这里有两个冒号? span :: before的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在看的整行代码,这里是它的上下文:

This is the full line of code I'm looking at, and here is its context: http://acidmartin.wordpress.com/2011/02/24/custom-crossbrowser-styling-for-checkboxes-and-radio-buttons

input[type="radio"] + span::before { content: ""; display: inline-block; width: 20px; height: 20px; background: url("sprite.png") no-repeat -20px 0; vertical-align: middle; }

我有一个很好的理解这是如何工作,但我不明白为什么有两个冒号,而不是span和之前的冒号。

I have a decent understanding of how this works, but I don't understand why there are two colons, rather than one between span and before.

前面的选择器,从我读过的应该使用一个冒号。

The before selector, from what I've read should use one colon.

在w3c上,我找不到有两个冒号的选择器,也不知道为什么span会有冒号,以及之前的冒号。

On w3c, I can't find any selectors that have two colons, nor can I figure out why span would have a colon following it, in addition to the colon preceding "before".

推荐答案

这是一个伪元素,由规范定义:

It's a pseudo-element, as defined by the CSS Selectors Level 3 spec:

它实际上与由第2级规范定义的单冒号语法。第3级规范引入了一个额外的冒号来区分伪元素和伪类(使用单个冒号)。

It is effectively the same as the single-colon syntax defined by the level 2 spec. The level 3 spec introduces an extra colon to differentiate between pseudo-elements and pseudo-classes (which use a single colon).

这两种语法都适用于较新的浏览器,但是旧版浏览器不会识别较新的 :: 样式。

Both syntaxes will work in newer browsers, but older browsers will not recognise the newer :: style.

有关更详细的信息,您可以查看第3级规范中的,其中规定:

For even more detail, you can look at the grammar from the level 3 spec, which states:

这篇关于为什么这里有两个冒号? span :: before的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 00:32