我的代码如下:
<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
一样,宽度没有帮助,它会变宽。我该如何防止这种情况?
答案 0 :(得分:4)
有很多方法,取决于你想做什么。
如果您应用overflow:hidden
,则会隐藏溢出的文本。您可以在overflow:scroll;
之类的div中使用<td style="padding:8px; color:#333"><center><div style="overflow:scroll; width:625px;"><?=stripslashes($arr['signature']);?></div> </center></td>
这将为溢出文本创建一个滚动,仅适用于此单元格(需要为此方法提供宽度)。
Here overflow:scroll;
答案 1 :(得分:2)
尝试:
<td style="width: 160px; max-width: 160px;">
或
<td style="width: 160px; overflow-x: hidden;">
或两者一起。
见
http://www.highdots.com/forums/html/limit-width-table-cell-271764.html
答案 2 :(得分:0)
使用overflow属性:
<table width="625px" style="overfow: hidden;">
答案 3 :(得分:0)
使用“td”标记
上的溢出样式属性<td style="overflow-x: hidden;">your text here</td>
答案 4 :(得分: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>
已被弃用;请使用text-align CSS属性。)
答案 5 :(得分:0)
我记得花上几个小时。使用table-layout:fixed style。
<table style="width:625px;table-layout:fixed;overflow:hidden">
每列将采用其第一个单元格的大小。