2010-08-30 246 views
1

我有這樣的代碼:
HTML表格寬度

<table width="625px"> 
<tr style="background-color:#CCC; font-size:14px;"> 
    <td style="padding:8px; color:#333"><center><?=stripslashes($arr['signature']);?> </center></td> 
</tr>  

如果$arr['signature']是一個很長的字符串,這樣gjuytfdcrtrfdscvythgfvtfdgtrfdvbgfvcfgbdc寬度不幫助它去很寬。我怎樣才能防止呢?

回答

4

有很多方法,取決於你想做什麼。 如果您應用overflow:hidden,那麼飛出的文字將被隱藏。你可以使用overflow:scroll;在一個格內,如<td style="padding:8px; color:#333"><center><div style="overflow:scroll; width:625px;"><?=stripslashes($arr['signature']);?></div> </center></td> 這將爲溢出文本創建一個滾動條,只爲這個單元格(需要給這個方法設置寬度)。

Here一個例子爲overflow:scroll;

+0

其實只是這個答案幫助我,謝謝。 – 2010-08-30 17:17:02

0

使用overflow屬性:

<table width="625px" style="overfow: hidden;"> 
0

使用溢出樣式屬性的 「TD」 標籤

<td style="overflow-x: hidden;">your text here</td> 
0

參見表格寬度的部分在CSS2規範中:http://www.w3.org/TR/CSS2/tables.html#width-layout

粗略地說,表格將選擇指定寬度的最大值和列寬的總和。你必須限制列的寬度,也許通過在元素上設置一個寬度(你也可以在這裏選擇你的溢出風格)。

例子:

<table width="625px"> 
    <tr style="background-color:#CCC; font-size:14px;"> 
     <td style="padding:8px; color:#333; width: 625px; overflow: hidden; text-align:center"><?=stripslashes($arr['signature']);?></td> 
    </tr>  
</table> 

(另請注意,<center>已久棄用;請使用文本對齊的CSS屬性)

0

我記得上花費大量時間。使用表格佈局:固定樣式。

<table style="width:625px;table-layout:fixed;overflow:hidden"> 

每列都將佔用其第一個單元格的大小。