【前端】【css】伪元素定位

需求

在这里插入图片描述

实现

    <view class="intent-container">
      <text
        class="user-intent {{selectedType === 'real' ? 'active' : ''}}"
        catchtap="switchIntent"
        data-type="real"
      >真题</text>
      <view style="height: 48rpx;width: 2rpx;background-color: rgba(173,202,248,0.4);"></view>
      <text
        class="change-intent {{selectedType === 'sim' ? 'active' : ''}}"
        catchtap="switchIntent"
        data-type="sim"
      >模拟题</text>
    </view>
/* 意图切换 */
.intent-container {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #eff5fd;
  height: 96rpx;
  font-size: 32rpx;
  color: #666666;
  border-radius: 32rpx 0 0;
}

/* 每个文字容器 */
.intent-container text {
  flex: 1;
  text-align: center;
  position: relative; /* ✅ 新增,伪元素定位参照它 */
  padding: 18rpx 0;
  font-size: 28rpx;
  color: #666;
}

/* 激活状态 */
.intent-container .active {
  color: #333;
  font-weight: 600;
}

/* ✅ 下划线伪元素修正 */
.intent-container .active::after {
  content: '';
  position: absolute;
  bottom: 0rpx;                  /* 紧贴文字底部 */
  left: 50%;
  transform: translateX(-50%);
  width: 50rpx;                  /* 下划线宽度 */
  height: 4rpx;
  border-radius: 4rpx;
  background-color: #4787F0;
  transition: all 0.3s ease;
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值