CSS 3.0 user-select property replacement

2019-06-16 21:10发布

问题:

I am using CSS 3.0 and it is complaining that the "user-select" property doesn't exist. Does anyone know what the appropriate substitute or replacement is?

回答1:

There doesn't appear to be one. user-select was defined as part of User Interface for CSS3, which was later superseded by CSS3 Basic User Interface Module. However, the latter document does not include specification of user-select. After searching recently, I was unable to find any discussion on why it might have been removed from the spec.

Note that user-select doesn't work in any browsers (that I'm aware of), though the vendor prefixed versions will work in Firefox, Chrome, Safari, Opera and IE 10+:

#something {
    -ms-user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
}

If you use only these vendor-prefixes, your CSS should validate if you set Vendor Extensions to Warning. For IE and Opera, you can use the unselectable attribute on elements. Ironically, though, this will invalidate your HTML.

See my answer on disabling text selection is not working in IE using jquery.