简体   繁体   English

更改空白背景色

[英]Change white space background color

如果仅在空白&nbsp可以更改div中文本的背景颜色?

Yes. 是。 Put it in a span element so that the element isn't larger than the text and set the background-color of this element. 将其放在span元素中,以使该元素不大于文本,并设置该元素的背景色。

<div><span style="background-color:red;">&nbsp;</span></div>

Yes, why wouldn't it? 是的,为什么不呢? What did you try? 你尝试了什么? For example, the following works ok: 例如,以下工作正常:

<div style="background-color: green">&nbsp;</div>

Background color can be set even if the element's content is completely empty, <div></div> . 即使元素的内容完全为空,也可以设置背景色<div></div> Its height will be zero by default, so the background color has no effect, but if you set the width property to nonzero, you will see the background in the color set. 默认情况下,其高度将为零,因此背景颜色无效,但是,如果将width属性设置为非零,则会在颜色集中看到背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM