td 內(nèi)容自動換行 table表格td設(shè)置寬度后文字太多自動換行
發(fā)布時間:2022-12-16 16:02:12 作者:佚名
我要評論

table表格td設(shè)置寬度后文字太多導(dǎo)致自動換行,這是一個很常見的問題,或許很多的網(wǎng)友已經(jīng)有了好的解決方法,如果依然有童鞋們不會的,可以參考下本文,可能會有意外的收獲
設(shè)置table 的 style="table-layout:fixed;" 然后設(shè)置td的 style="word-wrap:break-word;" 即可
但這種情況下表格寬度自由分配,所以如果不用設(shè)置table 的 style="table-layout:fixed;"直接使用下面的代碼也可以實現(xiàn)換行
word-wrap:break-word;word-break:break-all;
案例
<table style="TABLE-LAYOUT: fixed" border="1" cellspacing="0" cellpadding="0" width="200"> <tbody> <tr> <td style="WORD-WRAP: break-word" width="20">sssssssssssssssssssssssssssssssssssssssssssssss </td> <td>aaaaa</td> </tr> <tr> <td style="WORD-WRAP: break-word" width="20">sssssssssssssssssssssssssssssssssssssssssssssss </td> <td>aaaaa</td> </tr> </tbody> </table>
例子二
<table border="1" cellspacing="0" cellpadding="0" width="200"> <tbody> <tr> <td style="word-wrap:break-word;word-break:break-all;" width="20">sssssssssssssssssssssssssssssssssssssssssssssss </td> <td>aaaaa</td> </tr> <tr> <td style="word-wrap:break-word;word-break:break-all;" width="20">sssssssssssssssssssssssssssssssssssssssssssssss </td> <td>aaaaa</td> </tr> </tbody> </table>
比較好的寫法
#soft-intro table{border:1px solid #cccccc; border-collapse:collapse; text-align:center; margin-top:0.54em; clear:both;width: 100%;} #soft-intro table th,#soft-intro table td{padding:8px; border:1px solid #dddddd;line-height:22px; text-align:left} #soft-intro table th{background:#f9f9f9;} #soft-intro table thead, #soft-intro table.jbborder tr {background-color:#fff;} #soft-intro table tr:nth-child(even){background-color:#f9f9f9} #soft-intro table tbody tr:hover {background: rgba(255,255,153,.4)} #soft-intro table th img{display:block; margin:5px auto 0;} #soft-intro table td{text-align:left;word-wrap:break-word;word-break:break-all;} #soft-intro table td.version{font-weight:bold;} #soft-intro table pre{width:auto;margin:0;padding:0;border:0;background:transparent} #soft-intro table td p{margin:0; padding:0;line-height:22px;word-wrap:break-word;word-break:break-all;} #soft-intro table ul{margin-top:2px;}
相關(guān)文章
- 這篇文章主要介紹了html解決table設(shè)置寬度無效的問題,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學2020-07-30
- 這篇文章主要介紹了HTML頁面自適應(yīng)寬度的table(表格),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習2020-06-16
固定 table寬度 table-layout: fixed
如果單元格中的文本超過寬度限制,就會自動換行,高度自動增高,導(dǎo)致整個表格的樣式參差不齊,不過可以通過禁用文本換行來解決這個問題2014-05-15表格設(shè)置table-layout:fixed后對單元格寬度設(shè)置無效
在對設(shè)置表格設(shè)置table-layer:fixed樣式后,發(fā)現(xiàn)表格中有一行合并過,其它沒有合并的行的列寬會平均化,對列寬的設(shè)置會失效,下面有詳細的解決方法,大家可以學習學習2014-04-14html中table為每個單元格設(shè)置不同顏色和寬度
最好不要在table里面直接設(shè)置寬度,高度等,在style里面添加設(shè)置,就不會出現(xiàn)無效問題,代碼直接拷貝到body中間即可使用,下面有個示例,大家可以參考下2014-04-11- 頁面中table寬度設(shè)置width之后,寬度仍然不是固定的,文字太長后不換行,下面有個不錯的方法可以有效解決這個問題2014-02-17
html table呈現(xiàn)個人簡歷以及單元格寬度失效的問題解決
這篇文章主要介紹了html table呈現(xiàn)個人簡歷以及單元格寬度失效的問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下2021-01-22