一些实用的导航样式

伪类三角形高亮

直接撸代码,再看下面的一些解析。

<!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>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
    body{
        background: #f3f7fa;
    }
    ul{
        position: relative;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        width: 50%;
        height: 45px;
        padding: 0;
        margin: 50px 100px 0 ;
        border-top:dashed 1px #e8e8e8;
    }
    ul>li{
        position: relative;
        height: 45px;
        line-height: 45px;
        padding: 0px 25px;
        list-style-type: none;
    }
    ul>li.active{
        border-top: red solid 1px ;
        z-index: 20;
        color: red;
    }
    ul>li.active::before{
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translate(-50%,0);
        /*绘制三角形*/
        width:0;
        height:0;
        border-right:6px solid transparent;
        border-left:6px solid transparent;
        border-top:6px solid red;
    }
    </style>
</head>
<body>
    <ul>
        <li>
            <p>首页</p>
        </li>
        <li class="active">
            <p>个人中心</p>
        </li>
        <li>
            <p>不知道</p>
        </li>
    </ul>
</body>
</html>

效果如下:
在这里插入图片描述
在这里插入图片描述

  • 这里的三角形可以放在下面,即改为对应的li标签border-bottom,以及伪类:before改为:after 定位bottom无,top无 ;
  • 其中三角形居中定位效果transform: translate(-50%,0);

border边框高亮

一样直接撸代码

<!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>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
    body{
        background: #f3f7fa;
    }
    ul{
        position: relative;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        width: 50%;
        padding: 0;
        margin: 50px 100px 0 ;
    }
    ul::before{
        content: '';
        width: 100%;
        height: 1px;
        background: #e8e8e8;
        position: absolute;
        bottom: 0;
        left: 0;
    }
    ul>li{
        position: relative;
        padding: 5px 25px;
        list-style-type: none;
    }
    ul>li.active{
        border: solid 1px #e8e8e8;
        border-bottom: none; 
        background: #fff;
        z-index: 20;
    }
    </style>
</head>
<body>
    <ul>
        <li>
            <p>首页</p>
        </li>
        <li class="active">
            <p>个人中心</p>
        </li>
        <li>
            <p>申请加入</p>
        </li>
    </ul>
</body>
</html>

效果如下:
在这里插入图片描述

  • 这里要注意的是z-index,当然放这个更好,有些浏览器不用也行。
  • 这里还添加了北京色高亮。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值