Html 仅在文本上设置背景颜色,而不是 td 中的空白区域
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8714021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set background-color on only the text not the empty space in a td
提问by TrySpace
I'm trying to get the background color to wrap around the text alone, not the empty spaces.
我试图让背景颜色单独环绕文本,而不是空白区域。
I now have:
我现在有:
<TD> Text <BR><BR>
Longer text that stretches out above text-background color...
</TD>
and css:
和CSS:
td {background-color: black; color: white}
The rest of the space I would like just to be transparant, but I can't find any variable for this...
其余的空间我只想透明,但我找不到任何变量......
采纳答案by Pranay Rana
try span as given below will do your work.....
尝试下面给出的跨度将完成您的工作.....
<TD> <span> Text <BR><BR> Longer text that stretches out above text-background color...
</span></TD>
span {background-color: black; color: white}
回答by Rodik
try display:inline;
:
尝试display:inline;
:
td {background-color: black; color: white; display:inline;}
回答by Pekka
Put a <span>
around the text, and give that the background colour.
<span>
在文本周围放置一个,并为其指定背景颜色。