2011-12-18 384 views
0

我想仅在表格的1个单元格中放置背景图片。当我在表格标签中指定或'样式'背景被应用于整个屏幕时。是否有可能指定不同的本地图像到一个表中的不同单元格只使用HTML?背景图片

相关的HTML(从评论由OP):

<table align="center" height=501 border=2> 
     <tr> 
      <td height=167 align="center" style="background: (C:\Users\user\Desktop\4R9EF00Z.jpg);">[here] <a href="table9_1.html" target="_self"> Apple pie </a>s</td> 
      <td rowspan=3 width="80%"> <b>Ingredients</b> .........</td> 
     </tr> 
    </table> 
+0

你能发布您的代码? – 2011-12-18 18:05:57

+0

表9 <表ALIGN = “中心” 高度= 501的边界= 2> [这里] Apple pie 小号 成分 ......... – user1104759 2011-12-18 18:15:52

+0

@ user1104759,请使用问题标签下方的'编辑'链接,并在其中添加您的代码(可以使其更清晰)。 – 2011-12-18 18:18:26

回答

0

细胞的<td>元素只需使用内联CSS。

例如:

<td style="background: url(/resources/images/background.png);"> 
0

指定你的背景(使用样式属性)为<td>标签(或<th>标签)

0

你必须把它指定到小区(td标签),而不是整个的表。 像这样做:

<tr><td style="background-image:url('yourPath')"></td></tr> 
0

使用CSS有两种方式,分配id到小区:

#tableCellID { 
    background-image: url(path/to/image.png); 
} 

或者使用nth-child

tbody tr:nth-child(2) td:nth-child(3) { 
    background-image: url(path/to/image.png); 

}

将两种方法合并为一个JS Fiddle demo

如果必须使用在线风格(和我衷心建议避免这一点,如果你可以):

<td style="background-image: url(path/to/image.png);">...</td> 

,或者可能(但它不建议使用):

<td background="path/to/image.png">...</td> 

但,请注意,我做不是建议,或支持,使用这些方法之一。当然最后的做法是可怕的,但如果它只是只有的方法,你可以采取...然后...只是不要告诉我你使用它。这太可怕了,它会让我几天内觉得内疚。

Updated the previous JS Fiddle demo

1
<table style="width: 100%; height: 300px; "> 
    <tr> 
     <td style="background-image:url(http://www.housecatscentral.com/kittens.jpg)">CELL ONE</td> 
     <td>CELL TWO</td> 
    </tr> 
</table> 

途径应用的样式:

  • 内嵌样式(通常不是优选的方法)
  • 类选择
  • CSS2/3层次选择器或伪类
  • ID选择
+0

我试过了..但力量工作.. – user1104759 2011-12-18 18:27:41

0

HTML:

<table> 

    <tr><th>Header 1</th><th>Header 2</th><th>Header 3</th></tr> 

    <tr> 

     <td class="cell">Cell 1</td> 
     <td id="cell">Cell 2</td> 
     <td style="background-color: yellow">Cell 3</td> 

    <tr> 

</table> 

CSS:

.cell { 
    background: url(http://forum.php.pl/uploads/profile/photo-50953_thumb.png); 
} 

#cell { 
    background: url(http://forum.php.pl/uploads/profile/photo-50953_thumb.png); 
} 

预览这里:http://jsfiddle.net/384An/