【问题标题】:DataTable not centering and not properly auto widthDataTable 未居中且未正确自动宽度
【发布时间】:2016-12-16 03:03:06
【问题描述】:

所以我在一个 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>

文本按预期居中,但是当我更改时 &lt;div id="ajax_table_header" style="width: 60%;"&gt;&lt;div id="ajax_table_header" style="width: auto;"&gt;

好像没有应用 css。

当我&lt;table id="ajax_table" style="width: auto"&gt; 时,只有表格缩小到可管理的大小,而搜索栏、分页和其他所有内容继续延伸到 div 的边缘。

我可以做些什么来使其居中并自动调整大小?

Jsfiddle:https://jsfiddle.net/nc45tz0d/1/

ajax_table_header 中摆弄display: table 之后似乎是解决方案

【问题讨论】:

    标签: jquery css datatables


    【解决方案1】:

    将此添加到您的 div 中

    <div id="ajax_table_header" style="width: 60%;margin-right:auto;margin-left:auto">
    

    【讨论】:

      猜你喜欢
      • 2017-05-16
      • 2011-08-04
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 2017-02-04
      相关资源
      最近更新 更多