Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use user-select to prohibit text selection in CSS

Shulou Source: shulou.com Published: 2022-06-03 08:11:38 10月03日 Update

This article mainly explains "how to use user-select to prohibit text selection in CSS". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use user-select to prohibit text selection in CSS".

User-select has two values:

None: users cannot select text

Text: users can select text

It should be noted that user-select is not a W3C CSS standard attribute, the browser support is incomplete, and each browser needs to be adjusted.

The code is as follows:

Body {

-moz-user-select: none; / * Firefox * /

-webkit-user-select: none; / * webkit browser * /

-ms-user-select: none; / * IE10*/

-khtml-user-select: none; / * early browser * /

User-select: none

}

IE6-9 has not found any related CSS attributes.

The code is as follows:

/ / IE6-9

Document.body.onselectstart = document.body.ondrag = function () {

Return false

}

Thank you for your reading, the above is the content of "how to apply user-select to prohibit text selection in CSS". After the study of this article, I believe you have a deeper understanding of how to use user-select to prohibit text selection in CSS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Selection text application browser browsing learning code content attributes text user two that is ideas situations articles more standards Firefox knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Redmi Apple Shulou Information