Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS pseudo-class for having clicked on a <button>

Tags:

css

It seems that :active only applies a background color at the instant when you have clicked on the <button> in the interim between click release. I basically would like to apply , if it exists, a pseudo-class that is invoked after the release of a click on a <button> element to demonstrate to the viewer that it has been toggled.

button:active{
   background:#FFFFFF;
}

UPDATE:

I changed the <button> to be an anchor tag. However, when I try

 #button-id:visited{ background:#FFFFFF;  }

It doesn't render the background color after I click the <a>

Here is the Fiddle:

https://jsfiddle.net/y5apt5et/

like image 793
Thalatta Avatar asked Oct 18 '22 22:10

Thalatta


1 Answers

Here's a list of all CSS pseudo-classes. There's nothing that works as a toggle button. Your best bet is to add an event listener that listens for a click on the button and adds or removes a class that represents being toggled.

like image 183
Luke Hansford Avatar answered Oct 21 '22 23:10

Luke Hansford