HTML tab interface using only CSS

前端 未结 4 447
庸人自扰
庸人自扰 2020-12-03 16:46

is it possible to create a tabbed interface using just css, no javascript? I mean to be able to switch the tabs using css/html, without javascript. Maybe with CSS 3.0?

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 17:12

    :target is generally the preferred way of doing tabs.

    You can also be clever with input:radio, or input:checkbox elements.

    http://jsfiddle.net/nzYnc/

    HTML:

    
    
    
    
    
    
    First content
    Second content
    Third content

    CSS:

    input
    {
        position: absolute;
        right: 100%;
    }
    
    input:checked + div
    {
        display: block;
    }
    div
    {
        display: none;
    }
    

    Using the next-sibling (+) and :checked selectors in clever ways can allow you to do a pure CSS accordion, toggleable lists, or tabs like this.

提交回复
热议问题