純css 實現tab效果

原理:
1、radio 與a 重疊,
2、radio zindex屬性比a大,
3、radio透明
參考 http://www.imooc.com/video/7144

<html>
<head>
    <style type="text/css">
        .nav {
            position: fixed;
            bottom: 10px;
            width: 100%;
            height: 50px;
        }

        input, a {
            position: absolute;
            width: 20%;
            height: 100%;
        }

        input {
            z-index: 100;
            opacity: 0;
        }

        a {
            text-decoration:none;
            text-align: center;
            background: yellow;
            line-height: 50px;
        }

        .nav_item1, .nav_item1 + a {
            left: 0%;
        }

        .nav_item2, .nav_item2 + a {
            left: 20%;
        }

        .nav_item3, .nav_item3 + a {
            left: 40%;
        }

        .nav_item4, .nav_item4 + a {
            left: 60%;
        }

        .nav input:checked + a {
            background-color: #ff0000;
            font-size: 26px;
        }
    </style>

</head>
<body>
<div class="nav">
    <input type="radio" name="nav_radio" checked="checked" class="nav_item1">
    <a href="#">aa</a>
    <input type="radio" name="nav_radio" class="nav_item2">
    <a href="#">bb</a>
    <input type="radio" name="nav_radio" class="nav_item3">
    <a href="#">cc</a>
    <input type="radio" name="nav_radio" class="nav_item4">
    <a href="#">dd</a>
</div>
</body>
</html>
<html>
<head>
    <style type="text/css">
        .nav {
            position: relative;
        }

        .nav-item {
            display: inline-block;
            width: 20%;
            height: 50px;
            margin-left: 10px;
            position: relative;
        }

        input {
            position: absolute;
            top: 0px;
            left: 0px;
            width: 100%;
            z-index: 100;
            height: 100%;
            opacity: 0;
        }

        a {
            position: absolute;
            top: 0px;
            width: 100%;
            height: 100%;
            text-align: center;
            background: yellow;
            line-height: 50px
        }

        .nav input:checked + a {
            background-color: #ff0000;
            font-size: 26px;
        }
    </style>

</head>
<body>
<div class="nav">
    <div class="nav-item">
        <input type="radio" name="nav_radio" checked="checked">
        <a href="#">aa</a>
    </div>
    <div class="nav-item">
        <input type="radio" name="nav_radio">
        <a href="#">aa</a>
    </div>
    <div class="nav-item">
        <input type="radio" name="nav_radio">
        <a href="#">aa</a>
    </div>
    <div class="nav-item">
        <input type="radio" name="nav_radio">
        <a href="#">aa</a>
    </div>
</div>
</body>
</html>

html簡單,css就要複雜點,
html 複雜,css就能簡單點,
html 簡單至上,後臺人員只要看html,當然結構簡單更好,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章