css实现页面标签的跳转

纯css实现页面标签的跳转

html代码:



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>tab</title>
    <style type="text/css">
        #main {
            width: 510px;
            margin: 100px auto 0;
            border: 1px solid #999;
            background-color: lightgreen;
        }

        label {
            display: inline-block;
            cursor: pointer;
            height: 52px;
            line-height: 52px;
            font-size: 16px;
            width: 70px;
            text-align: center;
            margin: 0 47px;

        }

        .radio {
            margin: 0;
            display: none;
        }

        .radio:nth-of-type(1):checked~label:nth-of-type(1) {
        /*当第一个radio是checked的input时选中下面的标签1增加样式*/
            color: #fff;
            border-bottom: 2px solid #fff;
            font-weight: bold;
        }

        .radio:nth-of-type(1):checked~.tab:nth-of-type(1) {
        /*当第一个radio是checked的input时选中下面的内容1增加样式*/
            display: block;
        }

        .radio:nth-of-type(2):checked~label:nth-of-type(2) {
            color: #fff;
            border-bottom: 2px solid #fff;
            font-weight: bold;
        }

        .radio:nth-of-type(2):checked~.tab:nth-of-type(2) {
            display: block;
        }

        .radio:nth-of-type(3):checked~label:nth-of-type(3) {
            color: #fff;
            border-bottom: 2px solid #fff;
            font-weight: bold;
        }

        .radio:nth-of-type(3):checked~.tab:nth-of-type(3) {
            display: block;
        }

        .tab {
            display: none;
            width: 100%;
            height: 240px;
            font-size: 24px;
            text-align: center;
            line-height: 240px;
            border-top: 1px solid #d8d8d8;
            background-color: #fff;
        }
    </style>
</head>

<body>
    <div id="main">
        <input checked="checked" id="radio" class="radio" type="radio" name="radio">
        <!--单选框radio-->
        <input id="radio1" class="radio" type="radio" name="radio">
        <input id="radio2" class="radio" type="radio" name="radio">
        <label for="radio">页签1</label>
        <!--for属性绑定上面的input标签-->
        <label for="radio1">页签2</label>
        <label for="radio2">页签3</label>
        <div class="tab">内容1</div>
        <div class="tab">内容2</div>
        <div class="tab">内容3</div>
    </div>
</body>

</html>

猜你喜欢

转载自blog.csdn.net/Everywhere_Shipoars/article/details/81198023