jquery - DataTable 不居中且自动宽度不正确

标签 jquery css datatables

所以我在 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: tableajax_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/

相关文章:

javascript - Android:未捕获类型错误:对象函数数组(){[ native 代码]}没有方法 'from'

html - CSS 3 列布局在大屏幕宽度下折叠

javascript - 为 DataTables aoColumnDefs 创建 JavaScript 数组(JSON 格式)

jquery - table.row 不是函数

javascript - 调用 Vex 对话框以避免代码重复的干净方法?

javascript - jQuery 选择器在 IE 中不起作用

jquery - 热得到类型为 'value' 的最后一个元素的 'input' 和某个 'name' 吗?

css - 将 Edge 动画转换为 CSS3

html - 列 CSS 空白

javascript - jQuery DataTable 行详细信息给出 "data is undefined"