::selection Back
::selection
CSS pseudo-element represents a portion(一部分) of the document that is highlighted by the user. For example, a portion of a page that is selected by the user using the mouse or any other pointing device.
::selection {
background-color: #222;
color: white;
}
::-moz-selection {
background-color: #222;
color: white;
}
blockquote::selection {
background-color: #aaa;
color: white;
}
See the Pen dGVGyp by aleen42 (@aleen42) on CodePen.
Note
- Only a subset of all CSS properties can be used to style a
::selection
:
categories | items |
---|---|
Color Properties | color , background-color , and text-shadow properties. |
- The
::selection
pseudo-element was drafted for CSS Selectors Level 3 but was removed before it reached the Candidate Recommendation status, and it is currently not part of any CSS module on the standards track. However, it is still implemented in most browsers, and is likely to remain so. - Using
text-shadow
in ::selection is only supported in Chrome, Safari, Opera, nd Firefox.