To disable a link using CSS, pointer-events property can be used, which sets whether the element in the page has to respond or not while clicking on elements. The pointer-events property is used to specify whether element show to pointer events and whether not show on the pointer. Show Below example illustrate the approach: Example 1: Below code shows the use of property-events where ‘a’ tag is disabled, with no cursor (disabled cursor pointer on ‘a’ tag)
Output: We can notice that although it looks like a link, nothing happens when we take pointer on it or click on it. Example 2: This code shows CSS which applies to an ‘a’ tag so that it looks like, that the link is disabled, to do so, color and text-decoration property can be used. We can use user-select property in CSS to disable text selection highlighting in HTML pages.It is not a standard feature, but available in all modern browsers except IE 9 & before. Using user-select:noneTo disable the text selection in HTML we need to give user-select property value as none. Go through the below example to understand if further.
I have added disable-select class to the second div now we will add user-select css property
But we have to add browser specific prefix before the user-select option for safari,firefox and internet explorer or edge. Chrome and opera supports non prefixed versions. In Google ChromeTo disable text selection highlighting in Google Chrome browser using CSS just set -user-select CSS property to none. And no prefix is required for Google Chrome and Opera Browsers.
In mozilla firefoxTo disable text selection highlighting in mozilla firefox browser using CSS just set -moz-user-select CSS property to none. And we need add -moz prefix before user-select property for mozilla firefox Browser.
In SafariTo disable text selection highlighting in Safari browser using CSS just set -webkit-user-select CSS property to none. And we need add -webkit prefix before user-select property for Safari Browser.
In IOS SafariTo disable text selection highlighting in IOS Safari browser using CSS just set -webkit-touch-callout CSS property to none.
In Internet Explorer/Edge usingTo disable text selection highlighting in Internet Explorer/Edge browser using CSS just set -ms-user-select CSS property to none. And we need add -ms prefix before user-select property for Safari Browser.
What does user-select property will do?user-select css property controls whether a text in a HTML element can be selected or not. It is not a standard feature. You can find more details about draft specification . user-select property valuesuser-select valuedescriptionnoneuser cannot select the texttextuser can select the textalluser can select the text with one clickautouser-select value depend upon its parent user-select optioncontainselection will be bound to particular elementelementIE version of user-select contain.user-select noneAs explained above, when we give user-select property value as none to an HTML element we cannot select the text inside the element including it’s children element.
user-select textWhen you give user-select property as text, user can select the text.
user-select allWhen we give user-select property as all. Text inside the element is automatically selected on context click.
user-select autouser-select auto behavior depends upon its parent element’s computed value of user-select
user-select containuser-select contain is not supported in other browsers except internet explorer. In IE we have to give user-select option as element instead of contain. So what exactly this user-select contain will do? When you give user-select as contain or element selection will be bound to that element and cannot be extended. Go through the below demo to understand it further. user-select CSS exampleWe will see all user-select options in one place. 0And the corresponding CSS values are 1As explained above user-select : contain option is only supported in IE, if you open the fiddle in IE, You can observe its behaviour the element selection cannot be extended beyond the element with class .text-selection-contain. |