本文翻译自:Can I have an onclick effect in CSS?
I have an image element that I want to change on click. 我有一个想要在点击时更改的图像元素。
<img id="btnLeft">
This works: 这有效:
#btnLeft:hover {
width:70px;
height:74px;
}
But what I need is: 但我需要的是:
#btnLeft:onclick {
width:70px;
height:74px;
}
But, it doesn't work, obviously. 但是,它显然不起作用。 Is it possible at all to have onclick
behavior in CSS (ie without using JavaScript)? 是否有可能在CSS中具有onclick
行为(即不使用JavaScript)?
#1楼
参考:https://stackoom.com/question/vBqP/我可以在CSS中使用onclick效果吗
#2楼
The closest you'll get is :active
: 你最接近的是:active
:
#btnLeft:active {
width: 70px;
height: 74px;
}
However this will only apply the style when the mouse button is held down. 但是,这只会在按住鼠标按钮时应