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
.
Thanks!
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
Try to check outline on button's focus:
If you have it, just set it to
none
.Each link has five different states:
link
,hover
,active
,focus
andvisited
.Link
is the normal appearance,hover
is when you mouse over,active
is the state when it's clicked,focus
follows active andvisited
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
orvisited
, then you can add the following CSS:A recommended order in your CSS to not cause any trouble is the following:
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're looking for a pure css option, try using the :focus pseudo class.
It is possible to do with CSS only by selecting active and focus pseudo element of the button.
See codepen: http://codepen.io/fennefoss/pen/Bpqdqx
You could also write a simple jQuery click function which changes the background color.
HTML:
CSS:
JavaScript:
Check out this codepen: http://codepen.io/fennefoss/pen/pRxrVG
If your button would be an
<a>
element, you could use the:visited
selector.You are limited however, you can only change:
I haven't read this article about revisiting the
:visited
but maybe some smarter people have found more ways to hack it.What is the code of your button? If it's an a tag, then you could do this:
Or you could use jQuery to add a class on click, as below: