是否可以控制或设置添加到表头作为行 css 的宽度。我试图从版本 1.9.4 的 dataTables-jquery 中检查它。但找不到任何解决方案。由于宽度的增加,对齐受到干扰。
我还在 HTML 中分配宽度,例如
<th width="20%">Bhairav</th>
但是当我检查控制台时,它看起来像
<th width="20%" class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" aria-label="" style="width: 12px;">Bhairav</th>
问题是 style="width: 12px;"正在从任何地方动态添加到它。?
谁能帮我解决这个问题吗?
最佳答案
style="width: 12px;"
当 dataTables 有 bAutoWidth: true
时添加。示例:
dataTables 1.9.4,默认 bAutowidth
(真)-> <强> http://jsfiddle.net/rrsn0ckL/
第一<th>
呈现为
<th width="30%" class="sorting_asc" ...style="width: 254px;">Rendering engine</th>
与bAutoWidth: false
同表-> <强> http://jsfiddle.net/rrsn0ckL/1/
第一<th>
呈现为
<th width="30%" class="sorting_asc" ...>Rendering engine</th>
所以使用bAutoWidth: false
避免 style="width: 12px;"
通知:<th>
width
属性是 HTML 4.01 特定的,不应再使用 -> https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th
而是使用 CSS 或内联样式 style="width:20%;"
。 CSS 示例:
table#example th:nth-child(1) {
width: 20%;
}
table#example th:nth-child(2) {
width: 20%;
}
等等
关于javascript - 数据表:How to control the <th> width of table .我正在使用Jquery -1.9.4版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30504210/