Block code instances of selected text through CSS rules

Source: Internet
Author: User
It is still necessary to disable the selection of text in certain scenarios, such as not wanting to have others copy their articles. We can solve this problem by using CSS+JS. In addition, it is pointed out here that User-select is not the official standard of the web, and that each browser provides support in the form of a private attribute.

Grammar

Formal Syntax:none | Text | All | Element

The code is as follows:

(-prefix-) User-select:none; (-prefix-) User-select:text; (-prefix-) User-select:all; (-prefix-) user-select:element;

The code is as follows:

. row-of-icons {-webkit-user-select:none;/* Chrome All/safari all */-moz-user-select:none;/* Firefox all */-ms-user-s Elect:none; /* IE + */</p> <p>/* No support for these yet,use at own risk */-o-user-select:none;user-select:none;}

IE compatibility

Currently in IE 10 and IE 10 version of the browser can use-ms-user-select this rule, but in earlier versions of IE, we can only be implemented by JavaScript to suppress the selection of text:

The code is as follows:

$ (EL). attr (' unselectable ', ' on '). CSS ({'-moz-user-select ': '-moz-none ', '-moz-user-select ': ' None ', '-o-user-select ') : ' None ', '-khtml-user-select ': ' None ',/* could also put this in a class */'-webkit-user-select ': ' None ',/* and add the C SS class here instead */'-ms-user-select ': ' None ', ' user-select ': ' None '}). bind (' Selectstart ', function () {return false;});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.