在個人表中,我將列中第一個單元格的寬度設置爲100px
。
可是,當此列中某個單元格中的文本太長時,列的寬度將變得超過100px
。 我怎麼能禁用這個擴展? css
只需添加<div>
標籤內<td>
或<th>
限定內部寬度<div>
。 這會對你有所幫助。 沒有別的辦法。 html
例如。 html5
<td><div style="width: 50px" >...............</div></td>
我所作的是: spa
設置td寬度: code
<td width="200" height="50"><!--blaBlaBla Contents here--></td>
使用CSS設置td寬度: htm
<td style="width:200px; height:50px;">
使用CSS將寬度再次設置爲max和min: get
<td style="max-width:200px; min-width:200px; max-height:50px; min-height:50px; width:200px; height:50px;">
它聽起來有點重複,但它給了我想要的結果。 要輕鬆實現這一點,您可能須要將CSS值放在樣式表的類中: it
.td_size { width:200px; height:50px; max-width:200px; min-width:200px; max-height:50px; min-height:50px; **overflow:hidden;** /*(Optional)This might be useful for some overflow contents*/ }
而後: io
<td class="td_size">
將class屬性放置到您想要的任何<td>
。 table
KAsun有正確的想法。 這是正確的代碼......
<style type="text/css"> th.first-col > div, td.first-col > div { overflow:hidden; white-space:nowrap; width:100px } </style> <table> <thead><tr><th class="first-col"><div>really long header</div></th></tr></thead> <tbody><tr><td class="first-col"><div>really long text</div></td></tr></tbody> </table>
若是您須要一個或多個固定寬度的列而其餘列應調整大小,請嘗試將min-width
和max-width
設置爲相同的值。
請參閱: http : //www.html5-tutorials.org/tables/changing-column-width/
在表標記以後,使用col元素。 你不須要結束標籤。
例如,若是您有三列:
<table> <colgroup> <col style="width:40%"> <col style="width:30%"> <col style="width:30%"> </colgroup> <tbody> ... </tbody> </table>