伪类三角形高亮
直接撸代码,再看下面的一些解析。
<!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,当然放这个更好,有些浏览器不用也行。
- 这里还添加了北京色高亮。