我試圖通過使用該background-color屬性以不同的顏色突出顯示單詞的每個字母,但我想將字母分開以使它們看起來像塊狀。問題是,當我增加 時letter-spacing,突出顯示的部分是不平衡的,而不是像我想要的那樣以字母為中心。這是一個極端的例子:
<mark style="background-color: red">t</mark><mark style="background-color: green">e</mark<mark style="background-color: blue">s</mark><mark style="background-color: yellow">t</mark>
mark
{
color: white;
letter-spacing: 1em;
}
背景在字母的右側比左側延伸得更遠。有沒有辦法讓字母在背景中居中,使其在兩側均勻突出?目前我 在每個字母周圍使用 s 并且完全避免使用letter-spacing,這很好,但是不需要添加任何字符的解決方案會更好。我目前使用的是:
<mark style="background-color: red"> t </mark><mark style="background-color: green"> e </mark<mark style="background-color: blue"> s </mark><mark style="background-color: yellow"> t </mark>
uj5u.com熱心網友回復:
如果它們已經在單獨的元素中,則可以只使用填充。
mark
{
color: white;
padding: 0 1em;
}
<mark style="background-color: red">t</mark><mark style="background-color: green">e</mark><mark style="background-color: blue">s</mark><mark style="background-color: yellow">t</mark>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/425594.html
上一篇:如何使div容器拱起來?
