我怎样才能强调"文本以获得相同的效果,就像你在" TEST"?
下看到的那样我尝试将TEST封装在Student
并添加绝对值:span
之后,但我认为这不是正确的方法,并且无法获得预期的结果。
这是HTML
position: absolute

答案 0 :(得分:2)
你说你试过:after
。这是正确的解决方案。请参阅下面的代码段。
您可以更改值
.striked {
position: relative
}
h1 {
text-align: center;
}
.striked:after {
height: 50%;
width: 150%;
left: -25%;
background: red;
content: "";
position: absolute;
bottom: 0;
z-index: -1
}

<h1 class="white hero-text">
<span class="thin">ALL THIS TEXT IS</span>
<br>
<span class="bold striked">A TEST</span>
</h1>
&#13;
答案 1 :(得分:1)
这样的东西?
body{
background: #333;
font-family: arial;
}
.hero-text{
color: #fff;
text-align: center;
}
.bold.striked{
position: relative;
color: #fff;
text-align: center;
width: 300px;
margin: 0 auto;
z-index: 2;
}
.bold.striked::before{
content: "";
height: 15px;
width: calc(100% + 50px);
position: absolute;
bottom: 5px;
left: 50%;
transform: translateX(-50%);
background: #4882d5;
z-index: -1;
}
&#13;
<h1 class="white hero-text">
<span class="thin">ALL THIS TEXT IS</span>
<br>
<span class="bold striked">A TEST</span>
</h1>
&#13;
答案 2 :(得分:1)
如上所述使用伪选择器:before
,并将span tag
仅添加到您想要border
底部样式的部分,如上图所示。
span{
display:inline-block;
position:relative;
}
span:before{
content:"";
width:100%;
height:10px;
background:yellow;
position:absolute;
bottom:3px;
z-index:-1;
}
&#13;
<h1 class="white hero-text">
ALL THIS TEXT IS
<br>
<span>A TEST</span>
</h1>
&#13;