- Css3 provides a feature of text selection.It means when user select some text we can apply styles to that text.
- Through this feature we can control whether user can select the text or not.
- The variation of these properties for different Browsers are -webkit-user-select, -moz-user-select,-ms-user-select, -o-user-select,user-select.
- These variations are because of this attribute does not included in css3 specification till now.
- This property has “none“, “element“, “all“, “text” ,”elements” possible values.
User Selection Example:-
<!DOCTYPE html>
<html>
<head>
<title>Css3 User Selection Text Demo</title>
</head>
<style>
p.no-selection-style {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
p.can-select-style{
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
-o-user-select: text;
user-select: text;
}
p.can-select-ry::-moz-selection {
background-color: red;
color: yellow;
}
p.can-select-ry::selection {
background-color: red;
color: yellow;
}
p.can-select-go::-moz-selection {
background-color: green;
color: orange;
}
p.can-select-go::selection {
background-color: green;
color: orange;
}
p.can-select-bw::-moz-selection {
background-color: blue;
color: white;
}
p.can-select-bw::selection {
background-color: blue;
color: white;
}
</style>
<body>
<p class="can-select-ry">This is first paragraph.Hi This is Sandeep.I am very much passionate about css3.This Demo is
for showing text selection in ccs3.
</p>
<p class="can-select-go">This is second paragraph.Hi This is Sandeep.I am very much passionate about css3.This Demo is
for showing text selection in ccs3.
</p>
<p class="can-select-bw">This is third paragraph.Hi This is Sandeep.I am very much passionate about css3.This Demo is
for showing text selection in ccs3.
</p>
<p class="no-selection-style">This is fourth paragraph.Hi This is Sandeep.I am very much passionate about css3.This Demo is
for showing text selection in ccs3.
</p>
</body>
</script>
</html>
Fire Bug Inspection:-
Output:-
- The Fourth line is not selectable as we have given the value as “none”.