CSS绘制标签导航栏

html:

<div class="bruce flex-ct-x">

    <div class="tab-navbar">

        <input type="radio" name="tabs" id="tab1" hidden checked>

        <input type="radio" name="tabs" id="tab2" hidden>

        <input type="radio" name="tabs" id="tab3" hidden>

        <input type="radio" name="tabs" id="tab4" hidden>

        <nav>

            <label for="tab1">标题1</label>

            <label for="tab2">标题2</label>

            <label for="tab3">标题3</label>

            <label for="tab4">标题4</label>

        </nav>

        <main>

            <ul>

                <li>内容1</li>

                <li>内容2</li>

                <li>内容3</li>

                <li>内容4</li>

            </ul>

        </main>

    </div>

</div>

css(scss):

.tab-navbar {

    display: flex;

    overflowhidden;

    flex-direction: column-reverse;

    border-radius: 10px;

    width300px;

    height400px;

    input {

        &:nth-child(1):checked {

            & ~ nav label:nth-child(1) {

                @extend .active;

            }

            & ~ main ul {

                background-color#f66;

                transform: translate3d(000);

            }

        }

        &:nth-child(2):checked {

            & ~ nav label:nth-child(2) {

                @extend .active;

            }

            & ~ main ul {

                background-color#66f;

                transform: translate3d(-25%00);

            }

        }

        &:nth-child(3):checked {

            & ~ nav label:nth-child(3) {

                @extend .active;

            }

            & ~ main ul {

                background-color#f90;

                transform: translate3d(-50%00);

            }

        }

        &:nth-child(4):checked {

            & ~ nav label:nth-child(4) {

                @extend .active;

            }

            & ~ main ul {

                background-color#09f;

                transform: translate3d(-75%00);

            }

        }

    }

    nav {

        display: flex;

        height40px;

        background-color#f0f0f0;

        line-height40px;

        text-aligncenter;

        label {

            flex: 1;

            cursorpointer;

            transition: all 300ms;

        }

    }

    main {

        flex: 1;

        ul {

            display: flex;

            flex-wrap: nowrap;

            width400%;

            height100%;

            transition: all 300ms;

        }

        li {

            display: flex;

            justify-contentcenter;

            align-items: center; 

            flex: 1;

            font-weightbold;

            font-size20px;

            color#fff;

        }

    }

}

.active {

    background-color#3c9;

    color#fff;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

韩召华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值