I looked at W3 schools website W3Schools which explained styling buttons with CSS. I need to specify a button style when it is clicked. What is the pseudo-class selector for this? e.g. the hover button is:
.button:hover{ }
The :active selector is used to select and style the active link. A link becomes active when you click on it. Tip: The :active selector can be used on all elements, not only links.
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.
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.
This button will appear yellow initially. On hover it will turn orange. When you click it, it will turn red. I used :hover and :focus to adapt the style. (The :active selector is usually used of links (i.e. <a>
tags))
button{ background-color:yellow; } button:hover{background-color:orange;} button:focus{background-color:red;} a { color: orange; } a.button{ color:green; text-decoration: none; } a:visited { color: purple; } a:active { color: blue; }
<button> Hover and Click! </button> <br><br> <a href="#">Hello</a><br><br> <a class="button" href="#">Bye</a>
If you just want the button to have different styling while the mouse is pressed you can use the :active
pseudo class.
.button:active { }
If on the other hand you want the style to stay after clicking you will have to use javascript.
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