aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/_doublecolon_selection/index.html
blob: ca1232e10d5fc34a3633b467270290d0302e9acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
title: '::selection'
slug: 'Web/CSS/::selection'
tags:
  - CSS
  - Layout
translation_of: 'Web/CSS/::selection'
---
<p>{{ CSSRef() }}</p>

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

<pre class="brush: css">::selection {
  background-color: cyan;
}
</pre>

<h2 id="允许属性">允许属性</h2>

<p>只有一小部分CSS属性可以用于<code>::selection</code> 选择器:</p>

<ul>
 <li>{{CSSxRef("color")}}</li>
 <li>{{CSSxRef("background-color")}}</li>
 <li>{{CSSxRef("cursor")}}</li>
 <li>{{CSSxRef("caret-color")}}</li>
 <li>{{CSSxRef("outline")}} and its longhands</li>
 <li>{{CSSxRef("text-decoration")}} and its associated properties</li>
 <li>{{CSSxRef("text-emphasis-color")}}</li>
 <li>{{CSSxRef("text-shadow")}}</li>
</ul>

<div class="blockIndicator warning">
<p>要特别注意的是,{{ cssxref("background-image") }} 会如同其他属性一样被忽略。</p>
</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">/* Legacy Firefox syntax (version 61 and below) */
::-moz-selection

{{CSSSyntax}}
</pre>

<h2 id="示例">示例</h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">This text has special styles when you highlight it.
&lt;p&gt;Also try selecting text in this paragraph.&lt;/p&gt;</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css">::-moz-selection {
  color: gold;
  background-color: red;
}

p::-moz-selection {
  color: white;
  background-color: blue;
}</pre>

<pre class="brush: css">/* 选中的文本是红色背景,金黄色的字体 */
::selection {
  color: gold;
  background-color: red;
}

/*选中的是蓝色背景,白色的字体的段落*/
p::selection {
  color: white;
  background-color: blue;
}</pre>

<h3 id="结果">结果</h3>

<p>{{EmbedLiveSample('示例')}}</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('CSS4 Pseudo-Elements', '#selectordef-selection', '::selection')}}</td>
   <td>{{ Spec2('CSS4 Pseudo-Elements')}}</td>
   <td>Initial specification</td>
  </tr>
 </tbody>
</table>

<div class="blockIndicator note">
<p><code>::selection</code> CSS伪元素选择器是CSS第3级选择器的草案,但是在被推荐使用前就被废弃。它现在在第4级伪元素选择器草案中。</p>
</div>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p>{{Compat("css.selectors.selection")}}</p>