所以我在 div 中有一个数据表,它应该进行宽度设置,另一个数据表将它居中:
<div style='text-align:center !important'>
eakjflsdj
<div id="ajax_table_header" style="width: 60%;">
lbah
<table id="ajax_table">
<thead>
<tr>
<th>ID</th>
<th>Reference</th>
<th>Date</th>
<th>Title</th>
<th>Site</th>
<th>Location</th>
</tr>
</thead>
</table>
</div>
</div>
文本按预期居中,但当我更改时
<div id="ajax_table_header" style="width: 60%;">
到
<div id="ajax_table_header" style="width: auto;">
好像没有应用 css。
当我<table id="ajax_table" style="width: auto">
只有表格缩小到可管理的大小,而搜索栏、分页和其他所有内容继续延伸到 div 的边缘。
我该怎么做才能使其居中并自动调整大小?
Jsfiddle:https://jsfiddle.net/nc45tz0d/1/
经过多次摆弄display: table
在 ajax_table_header
似乎是解决方案
最佳答案
将这个添加到你的div
<div id="ajax_table_header" style="width: 60%;margin-right:auto;margin-left:auto">
关于jquery - DataTable 不居中且自动宽度不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41176635/