html

CSS Disable hover Effect

In CSS, an element responds by starting transition effects whenever a user hovers over it. It is an effective method for enhancing user experience and is used to draw attention to the crucial components of a web page. To do so, you can set the “pointer-events” CSS property of the element with the value “none”.

This post will explain the method for applying the CSS disable hover effect.

How to Apply CSS Disable hover Effect?

To apply CSS to disable the hover effect, use the CSS “pointer-events” property and set the value of this property as “none”. To do so, follow the given instructions.

Step 1: Make a div Container

First, make a div container with the help of the “<div>” element and insert an id or class attribute with a specific name.

Step 2: Insert Heading

Next, utilize the heading tag and embed text inside the heading tag. For that purpose, the <h1> tag is used.

Step 3: Add “<a>” Tag

After that, add the “<a>” tag, and with the help of “href”, add a URL of the page the link navigates. Also, add a “class” attribute with a particular name and embed text in between the “<a>” tag to display:

<div id="main">

<h1> Linuxhint Official Website</h1>

<a href="https://linuxhint.com/" class="noHover">Linuxhint</a>

</div>

Output

Step 4: Style “div” Container

Access the div container by using the id value as “#main”:

#main{

margin: 50px;

padding: 30px;

border: 3px solid green;

background-color: rgb(173, 224, 173);

}

Then, apply the mentioned properties listed below:

  • margin” and “padding” both are utilized for specifying the space in the HTML page. Whereas the “margin” is used for adding space outside the boundary, and “padding” is for inside spacing.
  • border” defines a boundary around a particular element.
  • background-color” determines the color at the backside of the element.

Output

Step 5: Disable “hover” Effect

Access the “<a>” element with the class name as “.noHover”:

.noHover{

pointer-events: none;

background-color: rgb(240, 116, 116);

}

Next, apply the “pointer-events” property that regulates how HTML components react to mouse/touch, JavaScript click/tap, and active/hover CSS states as well as whether or not the cursor is displayed.

Output

That’s all about CSS disable hover effect.

Conclusion

To apply CSS to disable the hover effect, use the CSS “pointer-events” property and set the value of this property as “none”. The pointer-event property is utilized for regulating how HTML components react to mouse/touch, JavaScript click/tap, and active/hover CSS states, as well as whether or not the cursor is displayed. This post has demonstrated the method for applying CSS to disable hover effect.

About the author

Hafsa Javed