Hey people!
We developers, deal with HTML pages every second. Every HTML UI essentially has some text elements. It is very easy for a user to double-click this text and select it. And this makes them look bad. To solve the same, CSS presents many standard-compliant ways. Here is an approach to make the text unselectable.
HTML :
<p>
Selectable text.
</p>
<p class="noselect">
Unselectable text.
</p>
CSS :
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Chrome/Safari/Opera */
-khtml-user-select: none; /* Konqueror */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
not supported by any browser */
}
In this solution, selection is disabled, but the user will still think of it as a selectable text because the cursor changes. To keep the cursor static, add the following line to your CSS :
cursor: default;
Note that the user-select
is supported in all browsers at present with Internet Explorer 9 and earlier versions being the exceptions.
Also, aside from this, there is no way to disable text selection using standard CSS.
Keep Coding!
0 Comment(s)