首页 > 解决方案 > 如何使数据表中的内容居中

问题描述

我有一个数据表,里面有一个 css 正方形<td>,我想居中,但我不知道该怎么做。

未对齐正方形的图像:

在此处输入图像描述

到目前为止我已经尝试过:

th.dt-center, td.dt-center { text-align: center; }

columnDefs: [ { className: 'text-center', targets: '_all' }, ]

根据我在这个 SO question中看到的

我也试过:

<th style="text-align:center;"></th>
<td style="text-align:center;"></td>

它适用于<th>但不适用于<td>

我也尝试了这里提供的解决方案

"columnDefs": [
    {"className": "dt-center", "targets": "_all"}
]

到目前为止,我还没有设法以任何方式使广场居中

现场演示 JS BIN

标签: htmlcssdatatables

解决方案


margin: 0 auto;应该在.square课堂上工作。


推荐阅读