富有弹性的导航栏小标签Html+CSS

富有弹性的导航栏小标签Html+CSS

演示

html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>弹性导航栏</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="../Web/css/15.css">
</head>
<body>
    <div class="wrapper">
       <!--nav标签 多用于导航栏-->
       <nav>
        <input id="home" type="radio" name="tab" checked>
        <input id="comment" type="radio" name="tab">
        <input id="envelope" type="radio" name="tab">
        <input id="heart" type="radio" name="tab">
        <input id="user" type="radio" name="tab">
        <!--label标签 广泛的选中-->
        <label for="home" class="home">
            <a href="#">
                <i class="fa fa-home" aria-hidden="true"></i>Home
            </a>
        </label>
       <label for="comment" class="comment">
           <a href="#">
            <!--i标签 外部引入的图标-->
            <i class="fa fa-comment" aria-hidden="true"></i>Comment
           </a>
       </label>
       <label for="envelope" class="envelope">
           <a href="#">
            <i class="fa fa-envelope" aria-hidden="true"></i>Envelope
           </a>
       </label>
       <label for="heart" class="heart">
           <a href="#">
            <i class="fa fa-heart" aria-hidden="true"></i>Heart
           </a>
       </label>
       <label for="user" class="user">
           <a href="#">
            <i class="fa fa-user-circle-o" aria-hidden="true"></i>User
           </a>
       </label>
        <!--这个div实现选中滚动效果-->
       <div class="tab"></div>
       </nav>
    </div>
</body>
</html>

CSS

*{
    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,#a8edea,#fed6e3);
}
.wrapper{
    width: 60vw;
    height: 60px;
    background-color: #fff;
    line-height: 60px;
    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{
    text-decoration: none;
    position: relative;
    z-index: -1;
    color: #333;
    font-size: 20px;
    font-weight: 500px;
}
.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,#f09819,#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%;
}
posted @   Tqqj  阅读(125)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示