2011-12-18 258 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/