From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/css/_doublecolon_selection/index.html | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 files/zh-cn/web/css/_doublecolon_selection/index.html (limited to 'files/zh-cn/web/css/_doublecolon_selection/index.html') diff --git a/files/zh-cn/web/css/_doublecolon_selection/index.html b/files/zh-cn/web/css/_doublecolon_selection/index.html new file mode 100644 index 0000000000..ca1232e10d --- /dev/null +++ b/files/zh-cn/web/css/_doublecolon_selection/index.html @@ -0,0 +1,105 @@ +--- +title: '::selection' +slug: 'Web/CSS/::selection' +tags: + - CSS + - Layout +translation_of: 'Web/CSS/::selection' +--- +

{{ CSSRef() }}

+ +

::selection CSS伪元素应用于文档中被用户高亮的部分(比如使用鼠标或其他选择设备选中的部分)。

+ +
::selection {
+  background-color: cyan;
+}
+
+ +

允许属性

+ +

只有一小部分CSS属性可以用于::selection 选择器:

+ + + +
+

要特别注意的是,{{ cssxref("background-image") }} 会如同其他属性一样被忽略。

+
+ +

语法

+ +
/* Legacy Firefox syntax (version 61 and below) */
+::-moz-selection
+
+{{CSSSyntax}}
+
+ +

示例

+ +

HTML

+ +
This text has special styles when you highlight it.
+<p>Also try selecting text in this paragraph.</p>
+ +

CSS

+ +
::-moz-selection {
+  color: gold;
+  background-color: red;
+}
+
+p::-moz-selection {
+  color: white;
+  background-color: blue;
+}
+ +
/* 选中的文本是红色背景,金黄色的字体 */
+::selection {
+  color: gold;
+  background-color: red;
+}
+
+/*选中的是蓝色背景,白色的字体的段落*/
+p::selection {
+  color: white;
+  background-color: blue;
+}
+ +

结果

+ +

{{EmbedLiveSample('示例')}}

+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{ SpecName('CSS4 Pseudo-Elements', '#selectordef-selection', '::selection')}}{{ Spec2('CSS4 Pseudo-Elements')}}Initial specification
+ +
+

::selection CSS伪元素选择器是CSS第3级选择器的草案,但是在被推荐使用前就被废弃。它现在在第4级伪元素选择器草案中。

+
+ +

浏览器兼容性

+ +

{{Compat("css.selectors.selection")}}

-- cgit v1.2.3-54-g00ecf