[英]CSS “underline” text part
您说您尝试过: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>
像这样吗
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; }
<h1 class="white hero-text"> <span class="thin">ALL THIS TEXT IS</span> <br> <span class="bold striked">A TEST</span> </h1>
如前所述,使用伪选择器: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; }
<h1 class="white hero-text"> ALL THIS TEXT IS <br> <span>A TEST</span> </h1>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.