2014-01-23 120 views
0

我面臨的問題是,我的表中的TD仍在繼承表的寬度,儘管它自己的寬度明確設置。TD繼承表寬度

的代碼如下:

<div class="widget widget-new-products"> 
    <div class="widget-products"> 
     <table cellspacing="0" width="640px" cellpadding="0" border="0" align="center"> 
       <tr> 
        <td> 
          <img src="header.gif" alt="New Releases"> 
        </td> 
      </tr> 

         <tr style="font-size: 0;"> 

           <td width="30px"><img width="30px" height="95px" src="leftsep.gif" alt="" ></td> 

           <td width="85px"> 
            <a href="" title="" class="product-image"><img src="product1.jpg" width="85" height="85" alt="image" ></a> 
           </td> 

           <td width="100px"> 
            <a style="font-family:sans-serif; font-size:13px; line-height:14px; color:#444; font-weight:bold;" title="" href="">item 1</a> 
           </td> 

           <td width="100px" align="right"> 
            <p style="font-family:sans-serif; font-size:22px; line-height:24px; font-weight:bold; color:#e05371; margin:0 0 5px 0;">£30.00</p> 
            <a href=""><img src="view-product.jpg" height="30px" width="111px" alt="View Product"></a> 
           </td> 

           <td width="10px"> 
           </td> 

           <td width="85px"> 
            <a href="" title="" class="product-image"><img src="product2.jpg" width="85" height="85" alt="" ></a> 
           </td> 

           <td width="100px"> 
            <a style="font-family:sans-serif; font-size:13px; line-height:14px; color:#444; font-weight:bold;" title="" href="">item 2</a> 
           </td> 

           <td width="100px" align="right"> 
            <p style="font-family:sans-serif; font-size:22px; line-height:24px; font-weight:bold; color:#e05371; margin:0 0 5px 0;">£10.00</p> 
            <a href=""><img src="view-product.jpg" height="30px" width="111px" alt="View Product"></a> 
           </td> 

           <td width="30px"><img width="30px" height="95px" src="rightsep.gif" alt=""></td> 

         </tr> 

       <tr> 
        <td> 
          <img src="footer.gif" alt=""> 
        </td> 
      </tr> 

     </table> 
    </div> 
</div> 

具體而言,受到影響的TD是在表中的第一:

<td width="30px"><img width="30px" height="95px" src="leftsep.gif" alt="" ></td> 

其被繼承的640像素表寬度,而不是30px它應該是。

它似乎不管我改變什麼,問題仍然存在..我已經在本地和JSFiddle測試。

我沒有經驗的HTML,所以我不知道什麼問題。

更新的代碼

 <div class="widget widget-new-products"> 
    <div class="widget-products"> 
     <table cellspacing="0" width="640px" cellpadding="0" border="0" align="center" style="border-spacing: 0;"> 
       <tr> 
        <td colspan="8"> 
          <img src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/newsletter/new-releases.gif" alt="New Releases"> 
        </td> 
       </tr> 

       <tr> 

         <td width="30"><img width="30px" height="95px" src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/newsletter/new-releases-left.gif" alt="" ></td> 

         <td width="85"> 
          <a href="" title="" class="product-image"><img src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/catalog/product/cache/1/small_image/85x/9df78eab33525d08d6e5fb8d27136e95/1/_/1.jpg_14603.jpg" width="85" height="85" alt="image" ></a> 
         </td> 

         <td width="100"> 
          <a style="font-family:sans-serif; font-size:13px; line-height:14px; color:#444; font-weight:bold;" title="" href="">Clydie King - Direct Me - Inc Never Like This Before</a> 
         </td> 

         <td width="111" align="right"> 
          <p style="font-family:sans-serif; font-size:22px; line-height:24px; font-weight:bold; color:#e05371; margin:0 0 5px 0;">£30.00</p> 
          <a href=""><img src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/newsletter/view-product.jpg" height="30px" width="111px" alt="View Product"></a> 
         </td> 

         <td width="85"> 
          <a href="" title="" class="product-image"><img src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/catalog/product/cache/1/small_image/85x/9df78eab33525d08d6e5fb8d27136e95/4/_/4.jpg_14418.jpg" width="85" height="85" alt="" ></a> 
         </td> 

         <td width="100"> 
          <a style="font-family:sans-serif; font-size:13px; line-height:14px; color:#444; font-weight:bold;" title="" href="">T.M.V.S. - Don't Be Shy</a> 
         </td> 

         <td width="111" align="right"> 
          <p style="font-family:sans-serif; font-size:22px; line-height:24px; font-weight:bold; color:#e05371; margin:0 0 5px 0;">£10.00</p> 
          <a href=""><img src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/newsletter/view-product.jpg" height="30px" width="111px" alt="View Product"></a> 
         </td> 

         <td width="30"> 
          <img width="30px" height="95px" src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/newsletter/new-releases-right.gif" alt=""> 
         </td> 

       </tr> 

       <tr> 
        <td colspan="8"> 
         <img src="http://crazybeatweb1.cms.iwebcloud.co.uk/media/newsletter/new-releases-bottom.gif" alt=""> 
        </td> 
      </tr> 

     </table> 
    </div> 
</div> 

我現在有上面和下面的中間行,我無法擺脫的差距。

+0

你應該使用CSS來爲你的表格造型。 –

+0

我會推薦使用css文件來代替。如果你仍然想用table標籤來定義,不要使用px,比如

,或者內聯樣式(使用px):style =「width:100px」... – jvicab

回答

3

表中的每一行必須有相同數量的細胞。如果你想在一排使用較少的細胞,你必須明確地設置colspan屬性相匹配:

<tr> 
     <td colspan="9"> <!-- set this to the maximum number of cells there will be in a row --> 
      <img src="header.gif" alt="New Releases"> 
     </td> 
    </tr> 

你可以混合和匹配colspan

<tr> 
     <td colspan="5"> 
      <img src="header.gif" alt="New Releases"> 
     </td> 
     <td colspan="4"> 
      <img src="header.gif" alt="New Releases"> 
     </td> 
    </tr> 

但總必須始終匹配表中使用的最大單元格數。

此過程必須對錶中的每一行重複。

+0

這也需要最後的'

'與''完成。 –

+0

這工作,謝謝。不過,我現在在中間行上方和下方有間隙(我已用新代碼更新) – Shooshine

+0

中間行有多少個單元格?你在第一個代碼塊中有9個,但是在你的第二個塊中只有8個錯誤,使得'colspan =「9」'錯誤 – Turnip

0

我相信它應該是:

<td width="200"> 

<td style="width: 200px"> 
0

你有一個3行,但不同數量的單元格的表。 如果你想有一個單元格跨越整個表,像頁眉和頁腳做,你需要specifiy對他們行跨度是這樣的:

<tr> 
    <td rowspan="9"><img src="header.gif" alt="New Releases"></td> 
</tr> 

在這種情況下,9,因爲你的中間行有9個細胞。 否則瀏覽器將呈現錯誤的表格。