2011-06-07 66 views
0

我需要将背景图像应用于我的表格行和单元格。这可能通过CSS,Javascript或jQuery?将一个背景图像添加到一个单元格和单元格所在的行中

<table> 
<tr style="background:url(/images/expand_shadow-top.png) repeat-x top;"> 
    <td style="background:url(/images/expand_shadow-btm.png) repeat-x bottom;"></td> 
</tr> 
</table> 

如果这是不可能的,我可以尝试一些其他的方法。这将是理想的,但似乎并不奏效。

+0

将在这两个背景是所有“TR”和“TD”一样吗? – Sparkup 2011-06-07 21:13:53

回答

1

是的,这是可能的。但是你的表格单元格不包含任何内容,而且你也没有指定它的大小,因此什么也不会显示。

+0

+ 1好点。 – Tadeck 2011-06-07 21:01:00

0

这是可能的CSS,Javascript jQuery。你只需要在你的单元格中有一些东西,线路没有破坏的空间(&nbsp;)。您应用样式的方式可以(尽管我会建议停止使用内联样式 - 可能会将它们移动到HTML文档的<head>部分)。

+0

如果他愿意,他可以使用'table {empty-cells:show; }'强制'table'显示空单元格,只要定义了'width'和'height'(或'min-width' /'min-height')。 – 2011-06-07 21:43:27

+0

@David Thomas是的,有关'empty-cells'及其在主流浏览器中的支持的更多内容是[here](http://reference.sitepoint.com/css/empty-cells)。 – Tadeck 2011-06-07 22:24:47

0

是有可能与所有三个,这里是CSS和jQuery:

<style type="text/css"> 

#mytable tr{background:url(/images/expand_shadow-top.png) repeat-x top;} 
#mytable td{background:background:url(/images/expand_shadow-btm.png) repeat-x bottom;} 

</style> 
<table id="mytable"> 
<tr> 
    <td>something&nbsp;here</td> 
</tr> 
</table> 
<script type="text/javascript"> 

$('#mytable tr').css("background","url(/images/expand_shadow-top.png) repeat-x top"); 
$('#mytable td').css("background","background:background:url(/images/expand_shadow-btm.png) repeat-x bottom"); 

</script> 
相关问题