Default :target with CSS

后端 未结 5 470
深忆病人
深忆病人 2020-11-29 08:42

I have this CSS:


And this HTML:<

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 09:11

    I know this is an old question, but it's still relevant and I have another suggestion:

    Tab 1
    Tab 2
    
    
    
    
    
    Some content
    Some other content

    and the css:

    .tab {display:none}
    
    .default-tab {display:block}
    
    :target ~ .default-tab {display:none}
    
    #tab1:target ~ .tab1,
    #tab2:target ~ .tab2 {
      display: block
    }
    

    This lets you have the tabs ordered however you want, but if you're generating the html dynamically you'll need to generate the css dynamically. Or else choose a maximum number of tabs to support when you write the css.

提交回复
热议问题