Html 在 td 标签上显示背景图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15186795/
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
show background image on td tag
提问by Anders Arpi
I am trying to show the background image on tag td. and I have code
我正在尝试在标签 td 上显示背景图像。我有代码
<td style="background-image:url(../uploadimages/18-2-2013-23-33-01-Lighthouse.jpg);background-repeat:no-repeat;background-size:250px 180px;"></td>
<img src="../uploadimages/18-2-2013-23-33-01-Lighthouse.jpg" />
I test the path by using tag img and it get correct the path but I do not know it's not show in the background image on td tag.
我使用标签 img 测试路径,它得到正确的路径,但我不知道它没有显示在 td 标签的背景图像中。
thankyou very much
非常感谢您
回答by Anders Arpi
The td
won't show a background image because it hasn't got any content, hence there's no space in the td
to draw the background. The background-size
sets the size of the background, not the size of the container. Try width:250px;height:180px;
in the inline style for the td
- it should show the image.
该td
不会显示背景图片,因为它没有得到任何内容,因此没有空间,在td
绘制背景。该background-size
设置背景的大小,而不是容器的大小。尝试width:250px;height:180px;
使用内联样式td
- 它应该显示图像。
Here's a demonstration in jsfiddle. If you remove the width
and height
settings from the CSS you won't see the image.
这是 jsfiddle 中的演示。如果您从 CSS 中删除width
和height
设置,您将看不到图像。
回答by Arif Hosain
Proper Solution
正确的解决方案
First of all, you have to specify the width and height of td. Follow the example that will work properly---
首先,您必须指定td的宽度和高度。遵循将正常工作的示例---
<td style="background-image:url(../uploadimages/18-2-2013-23-33-01-Lighthouse.jpg);background-repeat:no-repeat;background-size:250px 180px; width: 250px; height: 180px;"></td>