gpt4 book ai didi

html - 获取 :after to add underline only under text and not the entire container

转载 作者:太空宇宙 更新时间:2023-11-03 21:08:10 25 4
gpt4 key购买 nike

我想要标题用 :after 方法加下划线。我正在让它部分工作。我想不通的是如何让下划线("after)仅位于 .slantTitleWrap 内的跨度文本下方。

有没有人看到我做错了什么?

.slantBlock2Title {
color: #4D4D4D;
font-size: 1.5rem;
font-family: 'Muli', sans-serif;
line-height: 1.5em;
}
.slantTitleWrap span:after {
content: '';
display: block;
width: 40%;
margin-top: 5px;
background: #b82222;
height: 2px;
}
<div class="slantTitleWrap">
<span class="slantBlock2Title">Uderline me</span>
</div>

最佳答案

您可以通过使用“display: inline-block”来实现这一点。

.slantBlock2Title {
color: #4D4D4D;
font-size: 1.5rem;
font-family: 'Muli', sans-serif;
line-height: 1.5em;
display: inline-block;
}
.slantTitleWrap span:after {
content: '';
display: block;
width: 100%;
margin-top: 5px;
background: #b82222;
height: 2px;
}
<div class="slantTitleWrap">
<span class="slantBlock2Title">Uderline me</span>
</div>

关于html - 获取 :after to add underline only under text and not the entire container,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50120368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com