仅在标题元素内的文本上获取背景色



这是我的HTML结构。

<h2>The heading text</h2>.

不,我只需要为文本提供背景颜色。 以及除文本之外的空间的另一个背景。

我可以使用纯 css 而不是在其中添加任何额外的元素来实现这一点吗? 我需要这样的输出

你可以这样做:

<h2> black text <span style="background-color: #333;  color: #ccc; "> grey text with dark background </span> another black text</h2>

您可以在标题标签或段落标签中设置范围样式

你可以

试试这个

<h2>My text <span style="background-color:  #333; ">your text</span> another text </h2>

这将为该特定文本提供所需的样式,包括背景颜色

你可以这样做

<h2><span style='color:green'>The</span> <span style='color:blue'>heading</span> 
<span style='color:red'>text</span></h2>.

最新更新