Is there a way to deactivate a hover effect once it has been clicked on?

I am in need of a CSS code that resembles the following:

div:hover {
 apply hover effect
}

div:onclick{
 trigger click event
 disable hover
}

The main objective is to deactivate the hover effect for ALL elements once I have selected one.

Answer №1

You can utilize the :active pseudo-class to style buttons.

button {
  cursor:pointer;
  outline:none;
  border:none;
}

button:hover {
  background:#ff9900;
}

button:active {
  background:red;
}
<button>Submit</button>

If you desire the styling to persist after clicking on the button, then you should use the :focus pseudo-class.

button {
  cursor:pointer;
  outline:none;
  border:none;
}

button:hover {
  background:#ff9900;
}

button:focus {
  background:red;
}
<button>Submit</button>

Answer №2

Check out this implementation for removing a class from a div using JavaScript after clicking:

 var box = document.querySelector(".box")

    box.addEventListener("click", function () {
        box.className = "";
    })
.box:hover {
    background-color: green;
}
 <div class="box">CONTENT</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the font size to fit the size of the button when resizing a md-button

Currently utilizing md-button with text inside An issue arises in low resolution where the text gets cut off, struggling to find a suitable solution If anyone has any suggestions on how to resolve this problem, please share. I have included screenshots ...

Tips for Placing a Div in a Precise Location

I'm currently working with Bootstrap and I'm attempting to replicate a layout similar to the one used by Twitter, as shown in the screenshot below. The specific part I'm struggling with is where the profile picture is located. I want to add ...

What is the method for setting a fixed size for a Bootstrap container?

Bootstrap 4 is the framework I am currently using. Below is the HTML code I have written: <div class="sprite container d-inline-block bg-info rounded p-1"> <span class="sprite-span-level">Top-right text over image</span> <img cl ...

Adding elements to a form with ASP and storing them in a database

This is the content of richiesta.html: <HTML> <BODY> <table border> //creating a basic table <tr> <td> <form ACTION="richiesta.asp"> //redirecting to richiesta.asp <table> //opening a table structure <tr>&l ...

Learn the steps to create a 3D carousel that spins on its own without the need for manual clicks and pauses once the

Looking for a solution to create a 3D carousel that rotates continuously without the need for buttons to be clicked, and pauses when the mouse hovers over it, then resumes rotation when the mouse is not hovering over it. var carousel = $(".carousel"), ...

Utilizing Z-index for the arrangement of DIVs and elements in a webpage

I am facing an issue with my website design where the content section overlaps with the banner. This causes the content section to be hidden behind the banner, and I need it brought to the front. The problem specifically lies with the search element on my ...

What is the best way to eliminate a white border that appears only on my ThreeJS website when viewed on a mobile device?

I initially suspected a potential issue with resizing the window, so I created a JavaScript function to handle it. However, that did not resolve the problem. Any other ideas on how to troubleshoot this? // If the user resizes the window, update camera a ...

Instructions for selecting a checkbox using boolean values

According to the HTML specification, you should use the checked attribute in the <input type="checkbox"> tag to indicate that it is checked. However, I only have a boolean value of either true or false. Unfortunately, I am unable to manipulate the b ...

When I utilize $router.push() to navigate to a different page, the back button will take me back to the previous page

Within my Vue project, there is an HTML page that I am working on. Here is the link to the page: https://i.sstatic.net/cbtqM.png Whenever I click on the "+"" button, it redirects me to this specific page: https://i.sstatic.net/0rmMD.png This page funct ...

Verifying element presence in Python with Selenium

My current task involves navigating through a website one page at a time by clicking on the element labeled next, identified in the HTML code as class="pg-next". As I progress, I anticipate reaching the end of the website, where the next element will no lo ...

What is the best way to include a maximum height in my ScrollToBottom element?

I am currently attempting to limit the maximum height of my component as adding user messages causes it to expand and stretch the whole page. However, I have been unsuccessful in setting a maxHeight property for the component. I am utilizing ScrollToBottom ...

Tips for eliminating the border surrounding the entire table in Material-ui

Is there a way to edit a table in Material-ui without displaying it as a card? I'm looking to remove the border around the entire table, but I couldn't find any information on how to do that. Can someone help me out? Here is a link about the com ...

An error occurred: [object Object] does not support the 'popup' method

I've been attempting to close the jQuery popup by using $('#partsPopup').popup("close"); However, I encountered an error stating that there is no method called "popup". Below is the sequence of scripts that I have followed. Any assistance wo ...

At times, the animation in SetInterval may experience interruptions

I have created an animation using a sequence of images. The animation runs smoothly with the setinterval function, but for some reason, it occasionally pauses. I've shared a fiddle where you can see this pause happening. Click Here to See the Unwante ...

Use Powershell to extract the content of a text box from a webpage and store it in a text file

I am currently developing a script that will navigate to a specific webpage and interact with it by clicking a run button to calculate a value. The calculated value will then be displayed in a read-only text area identified by the id="result Console". Here ...

Looking to reduce the size of a logo image within a container as you scroll down a webpage?

I've been working on creating a logo section for my website, but I'm struggling to make it shrink as users scroll down and expand back to its original size when they scroll up. I've tried various JavaScript and jQuery functions without succe ...

Interact with HTML style attribute using JavaScript

Is there a way to retrieve a specific CSS property from the style attribute of an HTML element, without considering the stylesheet or computed properties? For example: <div style="float:right"></div> function fetchStyleValue(element, propert ...

Instructions for implementing an inline toolbar in a contenteditable="true" feature

I am currently developing a page that allows users to edit its content directly on the page. To achieve this, I have set the attribute contenteditable="true" for all the elements within the page. My goal is to show an inline toolbar with basic editing op ...

How can I make an inline h1 with a span that is aligned to the end?

I am attempting to create the most basic react app possible and I want to design a header using Bootstrap 4. The header will have two parts: the first part on the left side and the second part on the right side. Currently, my code looks like this: <di ...

center commotion excitement vessel vertically

I am facing a dilemma once again and could really use a helping hand. I have created an exciting animation that I have placed within a Bootstrap 4 tab, but I'm struggling to center it vertically. Is there someone out there who could help me out? Tha ...