Javascript 如何为html页面中div内的文本内容提供背景色。

Javascript 如何为html页面中div内的文本内容提供背景色。,javascript,html,css,Javascript,Html,Css,我不需要为整个div指定背景色。我只需要有文本内容的背景色。请帮助我。希望这有帮助,或者您可以提供更好的解决方案 div { height:2em; width:20em; background-color:#333; text-align:center;} div span.textContent { background-color:#000; color:#FFF; } 您需要指定Background color属性 #box{ background-color : red;

我不需要为整个div指定背景色。我只需要有文本内容的背景色。请帮助我。

希望这有帮助,或者您可以提供更好的解决方案

div {
height:2em; 
width:20em;
background-color:#333;
text-align:center;}

div span.textContent {
background-color:#000;
color:#FFF; }

您需要指定Background color属性

#box{
    background-color : red;
}

我帮你在谷歌上搜索CSS文本突出显示

<p class="intro">
    Highlighting text on a web page can help bring important information immediately to
    the readers attention e.g., "<span style="background-color: #FFFF00">This text
    should is highlighted in yellow and probably caught your eye first.</span>"
</p>

请参阅:

使用span标记并应用背景色:FFFF00

<span style="background-color: #FFFF00;">In publishing and graphic design, lorem ipsum is a placeholder text commonly used to demonstrate the graphic elements of a document or visual presentation.</span>
这看起来像,


e、 g.p{background:yellow;}文本内容是否被标记包围?你能提供一些代码吗?将它包装在一个或标记中,并设置该标记的背景色。这个示例如何对OP有用?假设我的文本中有两行,我的第一行只包含两个字母,第一行的背景色覆盖整个宽度。有没有办法只给这两个字母加上背景色?你能不能创建一个提琴来解释你的代码到底是怎样的…如果我理解正确的话,这会对你有更多帮助