【问题标题】:Disable padding added by DataTables禁用 DataTables 添加的填充
【发布时间】:2021-07-20 15:10:17
【问题描述】:

我试图将我的表格标题文本居中,但由于 dataTables 样式表添加了 bootstrap 3 图标,我的文本略微向左移动。如何正确居中文本?

<table class="table table-bordered table-hover center-all" id="dataTable">
  <thead>
    <tr>
      <th scope="col" style="text-align: center">Name</th>
      <th scope="col" class="headerText">Result</th>
    </tr>
  </thead>
</table>

这是目前的结果:

编辑:

这是 dataTables 添加填充的地方,有没有办法禁用它?

【问题讨论】:

  • 你能把这些图标设置在样式表中的绝对位置吗?
  • 我们如何测试你写的东西?我们必须猜测?当涉及到asking a good question 时,您可能会发现阅读网站help section 很有用。为了获得您问题的最佳答案,我们希望看到您首先尝试使用minimal reproducible example 自己解决问题。这是question checklist,您可能会觉得有用...
  • 只用css就可以解决。在图标上尝试position: absolute; right:0 并设置position: relative。
  • @Kinglish 我不确定这是否可能,因为图标是由 dataTables 动态添加的。我可以这样做吗?

标签: javascript html css datatables


【解决方案1】:

通过将它添加到我的 css 文件来修复它,它删除了 DataTables 添加到 0px 的填充:

table.dataTable thead > tr > th.sorting_asc, table.dataTable thead > tr > th.sorting_desc, table.dataTable thead > tr > th.sorting, table.dataTable thead > tr > td.sorting_asc, table.dataTable thead > tr > td.sorting_desc, table.dataTable thead > tr > td.sorting {
  padding-right: 0px;
}

【讨论】:

    猜你喜欢
    • 2021-06-16
    • 1970-01-01
    • 2019-01-15
    • 2020-02-29
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    相关资源
    最近更新 更多