Is there any simple way make :focus & :active behave as :hover?
Usually i write:
.class a:hover, .class a:active, .class a:focus {...}
But i would like to write just a single :hover rule and :focus & :active will look the same
.class a:hover {...}
Focus states cannot be the same as the hover states. However the hover state should be included with the focus styles. Be aware of the thickness of lines used for a focus state.
: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.
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.
To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element (the hover behavior of which you want to disable) to “none”.
There is currently no better way to do so in CSS2/3.
However, you might want to use cssnext to use the @custom-selectors
and :matches()
syntax today.
With @custom-selectors
:
@custom-selector: --enter :hover, :focus, :active;
a:--enter { ... }
With :matches()
:
a:matches(:hover, :focus, :active) { ... }
:hover
, :active
and :focus
exist as three separate pseudo-classes for a reason. An element that matches one of these pseudo-classes isn't automatically going to match the other two (even though they're not mutually exclusive, i.e. an element can match two or three of them at the same time).
It's not possible to force an element to match a dynamic pseudo-class either through CSS or programmatically. If you want to apply styles to elements in all three of these states, you will have to specify them.
Selectors 4's :matches()
will alleviate the repetitiveness:
.class a:matches(:hover, :active, :focus)
but it is currently not implemented unprefixed anywhere just yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With