Change background on button click, using CSS only?

前端 未结 6 2141
囚心锁ツ
囚心锁ツ 2020-12-03 12:05

Is it possible to change the background color on button click; of the entire document, using only CSS and HTML5?

(e.g.: it\'s trivial in Ja

6条回答
  •  旧时难觅i
    2020-12-03 12:44

    You can (ab?)use the :target selector. This probably won't work in older browsers. Here's a super simple example I made that toggles the background when the link is clicked.

    The concept is to apply CSS styling to targeted elements. In the code below, clicking the link will target the body's ID, which applies the style in body:target (changing the background color).

    
        
            
        
        
            Click
        
    
    

    JSfiddle

提交回复
热议问题