Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS on Mouse Down

Tags:

css

Usually I would use :hover, but I want my website to be accessible on touchscreen media too.

I know I can use :active, but as soon as I let go of the mouse button, it goes back to its inactive state.

Effectively I want:

Mouse Down : Div goes green

Mouse Up: Div stays green

Mouse Down: Div goes red

Mouse Up: Div stays red

Instead of:

Mouse Down: Div goes green

Mouse Up: Div goes red

like image 528
theorise Avatar asked Apr 27 '10 21:04

theorise


People also ask

What is on mouse down?

The onmousedown event occurs when a user presses a mouse button over an element. Tip: The order of events related to the onmousedown event (for the left/middle mouse button): onmousedown.

What is mouse down action?

The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element.

How do I make an active button in CSS?

A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :hover selector to style links when you mouse over them.

What is mouseup event?

The mouseup event is fired at an Element when a button on a pointing device (such as a mouse or trackpad) is released while the pointer is located inside it. mouseup events are the counterpoint to mousedown events.


1 Answers

Without relying on jQuery:

The :active pseudo-class is used to apply css to elements while they're being clicked upon.

.button {   color: red; } .button:active {   color: green; } 
like image 80
Jordan Feldstein Avatar answered Sep 29 '22 21:09

Jordan Feldstein