Can I have an onclick effect in CSS?

后端 未结 12 1784
悲&欢浪女
悲&欢浪女 2020-11-21 06:42

I have an image element that I want to change on click.


This works:

#btnLeft:hover {
    width:7         


        
12条回答
  •  爱一瞬间的悲伤
    2020-11-21 07:36

    You can use pseudo class :target to mimic on click event, let me give you an example.

    #something {
      display: none;
    }
    
    #something:target {
      display: block;
    }
    Show
    
    Bingo!

    Here's how it looks like: http://jsfiddle.net/TYhnb/

    One thing to note, this is only limited to hyperlink, so if you need to use on other than hyperlink, such as a button, you might want to hack it a little bit, such as styling a hyperlink to look like a button.

提交回复
热议问题