Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between CSS3 :hover and :focus?

The CSS3 doc talks about :hover and :focus, which seem exactly the same to me. What are the differences between the two? What am I not seeing?

Thanks!

like image 208
Pete Wilson Avatar asked May 26 '11 19:05

Pete Wilson


People also ask

How do you use hover and focus?

Typically, a user will first hover over an element, then bring it to focus, then activate it. So, the best way to order your pseudo-class styles are :hover then :focus then :active .

What is the difference between hover and active?

Hover: It is the state that occurs by putting your cursor over the button. You cannot see this state using the keyboard. Active: Very simply, it is the state of an element that is active. For example, in our example, it is the state of interacting with the button.

What's the difference between active and focus?

:focus is when an element is able to accept input - the cursor in a input box or a link that has been tabbed to. :active is when an element is being activated by a user - the time between when a user presses a mouse button and then releases it.

What is the focus in CSS?

The :focus CSS pseudo-class represents an element (such as a form input) that has received focus. It is generally triggered when the user clicks or taps on an element or selects it with the keyboard's Tab key.


2 Answers

Hover is 'true' when the mouse pointer is over an element. Focus is true if the cursor is in that element. It's possible for hover to be false and focus true (e.g click in a text field then move the mouse away)

like image 113
Marc B Avatar answered Sep 20 '22 09:09

Marc B


:hover applies to any element that the mouse cursor is currently over. :focus refers to form focus, and is the current form element with focus. Roughly speaking, if you start typing, which element will you be filling?

like image 27
recursive Avatar answered Sep 20 '22 09:09

recursive