I was wondering if there was a way to change a button's style, in css, after it's been clicked, so not a element:active
.
To change the background color of the button, use the CSS background-color property and give it a value of a color of your taste. In the . button selector, you use background-color:#0a0a23; to change the background color of the button.
:active denotes the interaction state (so for a button will be applied during press), :focus may be a better choice here. However, the styling will be lost once another element gains focus.
Unfortunately, there is no :click pseudo selector. If you want to change styling on click, you should use Jquery/Javascript. It certainly is better than the "hack" for pure HTML / CSS.
If you're looking for a pure css option, try using the :focus pseudo class.
#style { background-color: red; } #style:focus { background-color:yellow; }
Each link has five different states: link
, hover
, active
, focus
and visited
.
Link
is the normal appearance, hover
is when you mouse over, active
is the state when it's clicked, focus
follows active and visited
is the state you end up when you unfocus the recently clicked link.
I'm guessing you want to achieve a different style on either focus
or visited
, then you can add the following CSS:
a { color: #00c; } a:visited { #ccc; } a:focus { #cc0; }
A recommended order in your CSS to not cause any trouble is the following:
a a:visited { ... } a:focus { ... } a:hover { ... } a:active { ... }
You can use your web browser's developer tools to force the states of the element like this (Chrome->Developer Tools/Inspect Element->Style->Filter :hov): Force state in Chrome Developer Tools
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