HTML+CSS TAB导航栏

效果演示

图片

这段代码实现了一个名为"Tab导航栏"的效果,它是一个基于CSS的导航栏,包含五个选项卡,每个选项卡都有一个带有渐变背景色的滑块,当用户点击选项卡时,滑块会滑动到相应的位置。同时,选中的选项卡会变为白色,未选中的选项卡会变为灰色。

Code

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TAB导航栏</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" href="./04-TAB导航栏.css">
</head>

<body>
    <div class="wrapper">
        <nav>
            <input type="radio" name="tab" id="home" checked>
            <input type="radio" name="tab" id="comment">
            <input type="radio" name="tab" id="envelope">
            <input type="radio" name="tab" id="heart">
            <input type="radio" name="tab" id="user">
            <label for="home" class="home" onclick="location.href='#';">
                <a><i class="fa fa-home" aria-hidden="true"></i>Home</a>
            </label>
            <label for="comment" class="comment" onclick="location.href='#';">
                <a><i class="fa fa-comment" aria-hidden="true"></i>Comment</a>
            </label>
            <label for="envelope" class="envelope" onclick="location.href='#';">
                <a><i class="fa fa-envelope" aria-hidden="true"></i>Envelope</a>
            </label>
            <label for="heart" class="heart" onclick="location.href='#';">
                <a><i class="fa fa-heart" aria-hidden="true"></i>Heart</a>
            </label>
            <label for="user" class="user" onclick="location.href='#';">
                <a><i class="fa fa-user" aria-hidden="true"></i>User</a>
            </label>
            <div class="tab"></div>
        </nav>
    </div>
</body>

</html>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(200deg, #e8e8e8, #a8edea, #d1fffc, #e8e8e8);
}

.wrapper {
    width: 60vw;
    height: 60px;
    line-height: 60px;
    background-color: #fff;
    box-shadow: 0px 5px 15px rgba(0, 0, 0, 0.25);
    border-radius: 50px;
}

.wrapper nav {
    display: flex;
    position: relative;
}

.wrapper nav label {
    flex: 1;
    width: 100%;
    position: relative;
    z-index: 1;
    cursor: pointer;
}

.wrapper nav label a {
    position: relative;
    z-index: -1;
    color: #333;
    font-size: 20px;
    font-weight: bold;
    text-decoration: none;
}

.wrapper nav label a i {
    font-size: 25px;
    margin: 0px 7px;
}

.wrapper nav input {
    display: none;
}

.wrapper nav .tab {
    position: absolute;
    height: 100%;
    width: 20%;
    left: 0px;
    bottom: 0px;
    background: linear-gradient(to right, #ff5858, #ff5858);
    border-radius: 50px;
    transition: 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.wrapper nav #home:checked~label.home a,
.wrapper nav #comment:checked~label.comment a,
.wrapper nav #envelope:checked~label.envelope a,
.wrapper nav #heart:checked~label.heart a,
.wrapper nav #user:checked~label.user a {
    color: #fff;
    transition: 0.6s;
}

.wrapper nav #comment:checked~.tab {
    left: 20%;
}

.wrapper nav #envelope:checked~.tab {
    left: 40%;
}

.wrapper nav #heart:checked~.tab {
    left: 60%;
}

.wrapper nav #user:checked~.tab {
    left: 80%;
}

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

耀南.

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

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

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

打赏作者

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

抵扣说明:

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

余额充值