简体   繁体   English

如何根据列宽换行

[英]how to wrap text based on width of the column

hi i have a table with diffrent column widths like below 您好,我有一张表格,不同的列宽如下

${"#goldBarList"} table tr td:first-child{width:5%;}
${"#goldBarList"} table tr td:first-child+td{width:5%;}
${"#goldBarList"} table tr td:first-child+td+td{width:6%;}
${"#goldBarList"} table tr td:first-child+td+td+td{width:7%;}
${"#goldBarList"} table tr td:first-child+td+td+td+td{width:7%;}
${"#goldBarList"} table tr td:first-child+td+td+td+td+td+td+td{width:11%;}
${"#goldBarList"} table tr td:first-child+td+td+td+td+td+td+td+td{width:11%;}
${"#goldBarList"} table tr td:first-child+td+td+td+td+td+td+td+td+td{width:11%;}
${"#goldBarList"} table tr td:first-child+td+td+td+td+td+td+td+td+td+td{width:11%;}
${"#goldBarList"} table tr:first-child{read-only:true; font-size:90%; font-weight:bold;

}

i used 我用了

${"#goldBarList"} table{
table-layout:fixed;
word-wrap:break-word;
}

to make the table fixed and to wrap the text in the cells. 固定表格并将文本包装在单元格中。 But the problem is it is not wrapping the text based on the width of the column. 但是问题在于它不是基于列的宽度来包装文本。 Means for 5% width and for 11% width it is wrapping text wider than 8 characters. 意思是5%的宽度和11%的宽度,它包装的文本宽度超过8个字符。 But i want to wrap the text based on column width. 但是我想根据列宽来包装文本。 How to do this..? 这个怎么做..?

If you want to Wrap the text in javascript, 如果您想在javascript中换行,

var getFormattedString  = function (str, length){
    if(str == null || str == '') return '';
    return (str.length>length)?(str.substr(0,length) + "...") : str;
}

Call the above function like following. 如下调用上述函数。

var name = "This is the long long long text";
$(selector).attr('title', name).html(getFormattedString (name, 10));

Where title attribute of the lement will display the default tooltip. 元素的标题属性将显示默认工具提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM