CSS 中的双冒号 (::) 是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16704049/
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
What does the double colon (::) mean in CSS?
提问by Dilhan Jayathilake
What does the double colon (::
) mean in CSS?
::
CSS中的双冒号 ( ) 是什么意思?
For example:
例如:
input[type=text]::-ms-clear { display: none; }
采纳答案by alex
It means pseudo elementselector. It means the elementto the right doesn't exist in the normal DOM, but can be selected.
这意味着伪元素选择器。这意味着右侧的元素在普通 DOM 中不存在,但可以被选中。
A pseudo-element is made of two colons (::) followed by the name of the pseudo-element.
伪元素由两个冒号 (::) 后跟伪元素的名称组成。
It was originally only a single colon, but was changed to differentiate it from pseudo classes(like :hover
, :first-child
, :not
etc). It's best to use :
for before
and after
pseudo elements since the single colon has better browser support, namely in earlier IE versions.
它最初只有一个冒号,而是改为从区分其伪类(如:hover
,:first-child
,:not
等)。最好使用:
forbefore
和after
伪元素,因为单冒号有更好的浏览器支持,即在早期的 IE 版本中。
回答by Niels Keurentjes
The ::
operator indicates you are selecting a pseudo element, one which does not actually exist as an element but can still be targeted for styling.
该::
运营商表示你选择一个伪元素,其中一个实际上并不存在的元素,但仍然可以有针对性地进行造型。
Example of this include several vendor-specific implementations such as the -ms-clear
sample you provide, most browsers also have pseudo elements to style scroll bars and other native UI elements, but there are also a lot of predefined pseudo elementswhich can be referenced for practical reasons, such as first-line
and first-letter
.
这方面的示例包括几个特定于供应商的实现,例如-ms-clear
您提供的示例,大多数浏览器还具有用于样式化滚动条和其他本机 UI 元素的伪元素,但也有许多预定义的伪元素可以出于实际原因进行引用,比如first-line
和first-letter
。
The :before
and :after
pseudo elements even allow you to insert actual content into the page using CSS with the content
rule.
在:before
和:after
伪元素甚至允许你插入实际内容为使用CSS与网页content
的规则。
回答by Eric Jablow
CSS3 changes the way pseudo-elements are selected, as the W3C wanted to distinguish pseudo-classes like a:visited
from pseudo-elements like p::first-line
. See Advanced CSS Selectors.
CSS3 改变了选择伪元素的方式,因为 W3C 希望区分a:visited
像p::first-line
. 请参阅高级 CSS 选择器。