gpt4 book ai didi

html - 自定义文本下划线(使用 + 和 - 符号)

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:22 26 4
gpt4 key购买 nike

我需要实现自定义文本装饰,见下图: Custom text underline design

用下一个样式模拟-行很简单:

color: red;
border-bottom: 3px dashed; // 3px - just for example, 2.5 also looks fine.

但我找不到如何使用 + 符号实现下划线。实际上,我知道可以使用 background-image,但如果文本很长,它就不起作用。

如果有任何帮助,我将不胜感激。提前谢谢你。

更新:可玩的简单代码片段:

<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>

最佳答案

你可以像下面这样用渐变来做到这一点:

.deleted {
background:
repeating-linear-gradient(to right,red 0 4px,transparent 4px 6px)
bottom/100% 2px no-repeat;
}
.added {
background:
repeating-linear-gradient(to right,green 0px 1px,transparent 1px 5px)
bottom 0 left 2px/100% 5px no-repeat,
linear-gradient(green,green) bottom 2px left 0/100% 1px no-repeat;
padding-bottom:4px;
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>

如果你想在+

之间留一些空格

.deleted {
background:
repeating-linear-gradient(to right,red 0 4px,transparent 4px 6px)
bottom/100% 2px no-repeat;
}
.added {
background:
repeating-linear-gradient(to right,green 0 1px,transparent 1px 7px)
bottom 0 left 2px/100% 5px no-repeat,
repeating-linear-gradient(to right,green 0 5px,transparent 5px 7px)
bottom 2px left 0/100% 1px no-repeat;
padding-bottom:4px;
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>

它也适用于多行文本:

.deleted {
background:
repeating-linear-gradient(to right,red 0 4px,transparent 4px 6px)
bottom/100% 2px no-repeat;
}
.added {
background:
repeating-linear-gradient(to right,green 0 1px,transparent 1px 7px)
bottom 0 left 2px/100% 5px no-repeat,
repeating-linear-gradient(to right,green 0 5px,transparent 5px 7px)
bottom 2px left 0/100% 1px no-repeat;
padding-bottom:4px;
}
<main>
<h1>Here goes some heading <span class="deleted">and this is deleted</span></h1>
<p>And here goes more text. <span class="added">This is long long long long long long long long long long text was inserted.</span> More text <span class="deleted">This was deleted</span></p>
</main>

关于html - 自定义文本下划线(使用 + 和 - 符号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57162775/

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