文字下方的横线随方向移动

这篇博客介绍了如何利用CSS样式实现文字下方的横线随着选中项的方向移动。通过设置`display: flex;`、`position: absolute;`等属性,结合伪元素`:before`和`:active`状态,实现了一个简单的导航条效果,当点击某个选项时,横线从当前选中项向左或向右平滑移动。
摘要由CSDN通过智能技术生成

这是 参考别人的思路和想法https://blog.csdn.net/g229191727/article/details/80731527

下面是自己写的 

.content-top {

display: flex;

border-bottom: 1rpx solid #f8f9fa;

padding-bottom: 20rpx;

}

.content-top-item {

flex: 1;

text-align: center;

font-size: 30rpx;

color: #1a2031;

position: relative;

}

.content-top-item.active {

color: #ff643a;

}

 

.content-top-item::before {

position: absolute;

content: ' ';

bottom: -20rpx;

width: 100%;

left: 100%;

text-align: left;

}

 

.content-top-item.active ~ .content-top-item::before {

left: -100%;

}

 

.content-top-item.active::before {

border-top: 1rpx solid #ff643a;

left: 0;

tr

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值