【问题标题】:SCSS - pseudo element to create underline in the middle of sentence [duplicate]SCSS - 在句子中间创建下划线的伪元素
【发布时间】:2020-06-09 21:39:01
【问题描述】:

我试图用伪元素在句子中间的一些文本下划线。下划线需要稍微覆盖文本的底部(“半体面”),如下图所示。需要下划线的文本包含在underline 类中。

正如在代码 sn-p 中看到的那样,我不能让它动态下划线 underline 类的宽度,也不能与 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>

【问题讨论】:

  • 那么你的问题是什么?你真正想强调哪一部分?
  • @Kenny 我编辑了答案以使其更清楚。包含在 underline 类中的文本(“半体面”)需要加下划线

标签: html css sass pseudo-element


【解决方案1】:

制作标签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>

【讨论】:

    【解决方案2】:

    你快到了

    你需要添加更多的 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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-13
      • 2015-01-17
      • 1970-01-01
      • 2016-07-09
      • 2020-01-06
      • 1970-01-01
      • 2015-01-16
      • 2019-06-08
      相关资源
      最近更新 更多