Hide Show content-list with only CSS, no javascript used

前端 未结 12 1568
长发绾君心
长发绾君心 2020-11-28 23:18

I\'ve been searching for a good trick to make a Hide/Show content or a list with only CSS and no javascript. I\'ve managed to make this action:



        
12条回答
  •  暖寄归人
    2020-11-29 00:10

    I used a hidden checkbox to persistent view of some message. The checkbox could be hidden (display:none) or not. This is a tiny code that I could write.

    You can see and test the demo on JSFiddle

    HTML:

    
    
    Do you need some help?
    

    CSS:

    #show,#content{display:none;}
    #show:checked~#content{display:block;}
    

    Run code snippet:

    #show,#content{display:none;}
    #show:checked~#content{display:block;}
    
    
    Do you need some help?

    http://jsfiddle.net/9s8scbL7/

提交回复
热议问题