Change div background color on click using only css

后端 未结 3 1962
予麋鹿
予麋鹿 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:26
    div:focus {
        background-color:'color';
    }
    
    0 讨论(0)
  • 2020-12-16 01:27

    Try this, it worked for me:

    div:active{  
    
        background-color:white;
    
    }
    
    0 讨论(0)
  • 2020-12-16 01:40

    Make your DIVs focusable, by adding tabIndex:

    <div tabindex="1">
    Section 1
    </div>
    
    <div tabindex="2">
    Section 2
    </div>
    
    <div tabindex="3">
    Section 3
    </div>
    

    Then you can simple use :focus pseudo-class

    div:focus {
        background-color:red;
    }
    

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

    0 讨论(0)
提交回复
热议问题