SCSS - 在句子中间创建下划线的伪元素

SCSS - pseudo element to create underline in the middle of sentence

我试图用伪元素在句子中间的一些文本下划线。下划线需要稍微覆盖文本的底部("half decent"),如下图所示。需要加下划线的文字包裹在underlineclass中。

正如在代码片段中看到的那样,我无法完全动态地在 class underline 的宽度下划线,也无法使其与 class 中的文本对齐underline

.h1{
  font-family: FreightBig Pro;
  font-style: normal;
  font-weight: 500;
  font-size: 48px;
  line-height: 61px;
  text-align: center;
}

.underline::after{
  content:"";
  display: block;
  position: absolute;
  width: 200px;
  height: 12px;
  background: rgba(7, 151, 144, 0.5);
}
<span class="h1">I send a <span class="h1 underline">half decent</span> email </br> every week on the state of design.</span>

你快到了

您需要添加更多 CSS 才能实现

喜欢

.underline {
    position: relative
}

.underline::after{
   content:"";
   display: block;
   position: absolute;
   left: 0;
   right: 0;
   bottom: 0;
   height: 12px;
   background: rgba(7, 151, 144, 0.5);
}

.h1{
  font-family: FreightBig Pro;
  font-style: normal;
  font-weight: 500;
  font-size: 48px;
  line-height: 61px;
  text-align: center;
}

.underline {
  position: relative
 }
 
.underline::after{
  content:"";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  background: rgba(7, 151, 144, 0.5);
}
<span class="h1">I send a <span class="h1 underline">half decent</span> email </br> every week on the state of design.</span>

制作标签position: relative;

设置:after元素的位置(left, right, bottom);

.h1{
  font-family: FreightBig Pro;
  font-style: normal;
  font-weight: 500;
  font-size: 48px;
  line-height: 61px;
  text-align: center;
  position: relative;
}

.underline::after{
  content:"";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  width: 100%;
  height: 12px;
  background: rgba(7, 151, 144, 0.5);
}
<span class="h1">I send a <span class="h1 underline">half decent</span> email </br> every week on the state of design.</span>