Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use :hover css when mouse is down

I have a dropdown menu that's part of a JavaScript app. It's part of a row of buttons which are styled in a seperate CSS file. The dropdown menu creates a column of buttons that should be styled the same as the originating row.

I need the buttons in the dropdown menu to respond with the same :hover CSS as the row, but I'm having trouble because the mouse must be down for the dropdown menu to be visible. I can take the rules from CSS and write them into the JS like so:

    jQuery(texDiv).mouseover( function() {
      this.style.color = '#000000';
    });

But, I would prefer to reference the :hover CSS rule in some way, so that it is only written in one place in the code. I could just make all of the buttons' hover style be handled by jQuery mouseover adding a class, but now I'm curious about how this can be done.

So, how can I reference/force :hover CSS to take effect when mouse is down? Please direct me if I have missed this answer elsewhere!

like image 704
maaachine Avatar asked Aug 31 '25 02:08

maaachine


2 Answers

simple solution - on mouseover add another class where you could define new color, and on mouseout remove it

like image 170
Ochi Avatar answered Sep 02 '25 15:09

Ochi


To force a :hover wouldnt be understood by other browsers imo. You can define a marker-class in css like this:

// your seperate file
a:hover, .marker {
   // all your needs
}

So you can easyly add a css-class to your

jQuery(texDiv).mouseover( function() {
  $(this).addClass('marker');
});
like image 33
Grim Avatar answered Sep 02 '25 15:09

Grim