datatable行內內容太長,有時不自動換行解決方法


加一個css屬性即可

style = "word-wrap:break-word;"

js代碼:

"render": function (data, type, full, meta) {
return '<p style="word-wrap:break-word;">' + data + '</p>'
}

但有時word-wrap會失效,原因如下:

  1.word-wrap對行內元素是沒有效果的

 
        

     2.一般情況下,元素擁有默認的white-space:normal(自動換行,不換行是white-space:nowrap),可能是元素中設置的white-space是norwrap導致,無法換行。所以需要設置:    

white-space:normal;
word-break:break-all;

在 td 里面 加上 style="word-wrap:break-word;" 自動換行就好了,如果不想換行,可以將超出內容設為隱藏,

overflow:hidden; 
white-space:nowrap;

 

(1)超過寬度和高度文字會自動隱藏

<div style="width:100px;height:25px;overflow-x:hidden;overflow-y:hidden;">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>

 

(2)設置了td的寬度超過長度自動換行

<td>
<div style="width:100px;word-wrap:break-word;" >cvcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc</div>
</td>
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM