Change div background color on click using only css

后端 未结 3 1960
予麋鹿
予麋鹿 2020-12-16 01:09

So I have a div I want to change the color of when clicked. I have three divs over all and I want to denote which one is the active div when clicking on it

Basically

3条回答
  •  时光说笑
    2020-12-16 01:40

    Make your DIVs focusable, by adding tabIndex:

    Section 1
    Section 2
    Section 3

    Then you can simple use :focus pseudo-class

    div:focus {
        background-color:red;
    }
    

    Demo: http://jsfiddle.net/mwbbcyja/

提交回复
热议问题