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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:59:16  来源:igfitidea点击:

What does the double colon (::) mean in CSS?

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.

伪元素由两个冒号 (::) 后跟伪元素的名称组成。

Source

来源

It was originally only a single colon, but was changed to differentiate it from pseudo classes(like :hover, :first-child, :notetc). It's best to use :for beforeand afterpseudo elements since the single colon has better browser support, namely in earlier IE versions.

它最初只有一个冒号,而是改为从区分其伪类(如:hover:first-child:not等)。最好使用:forbeforeafter伪元素,因为单冒号有更好的浏览器支持,即在早期的 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-clearsample 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-lineand first-letter.

这方面的示例包括几个特定于供应商的实现,例如-ms-clear您提供的示例,大多数浏览器还具有用于样式化滚动条和其他本机 UI 元素的伪元素,但也有许多预定义的伪元素可以出于实际原因进行引用,比如first-linefirst-letter

The :beforeand :afterpseudo elements even allow you to insert actual content into the page using CSS with the contentrule.

: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:visitedfrom pseudo-elements like p::first-line. See Advanced CSS Selectors.

CSS3 改变了选择伪元素的方式,因为 W3C 希望区分a:visitedp::first-line. 请参阅高级 CSS 选择器