如何将列放在一行中(引导表)

我想问一下如何垂直对齐表格列。例如,如果我有表x和表y,然后在表之间添加一些内容,如何将列放在同一行(垂直位于同一位置)。我尝试了引导程序类,但没有任何效果。我应该添加填充或边距吗?我也希望表响应(引导类表响应)。这是一个代码:https :
//codepen.io/S4UCY/pen/OJNWqzg?editors=1100

.container {
    position: relative;
  margin-right: auto;
  margin-left: auto;
  padding-left: 15px;
  padding-right: 15px;
}

.table td,
.table th {
  width: 50%;
  padding-left: 10px;
  word-break: break-word;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

<div class="container">
            <h2><i class="fas fa-home"></i> Table x</h2>
        <table class="table table-responsive">
          <thead>
            <tr>
              <th scope="col">Column 1</th>
              <th scope="col">Column 2</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.</td>
            </tr>
          </tbody>
        </table>
  <p>Suspendisse potenti. Sed eu dui at magna finibus vehicula. Suspendisse sagittis ipsum arcu. Quisque non elit et purus finibus vehicula. Vivamus faucibus tincidunt erat, sit amet auctor risus luctus nec. Nunc commodo tristique enim, et rhoncus</p>
    <h2><i class="fas fa-home"></i> Table y</h2>
    <table class="table table-responsive">
          <thead>
            <tr>
              <th scope="col">Column 1</th>
              <th scope="col">Column 2</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisisEtiam facilisisEtiam facilisis</td>
            </tr>
          </tbody>
        </table>
      </div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

蓬松的小猫

问题是.table-responsive该类display从默认值更改tableblock由于此类不会为您做任何其他事情(至少在您发布的代码中),因此只需将其删除即可-请参见下面的示例。

您还在评论中询问了如何将表格居中。当您使用bootstraps表类时,该表设置为100%,因此没有任何要居中的位置,因为它已经占用了整个宽度。

要使表格在页面中居中,首先需要设置想要的宽度(或最大宽度),然后再设置margin:auto,例如

.table { max-width:1000px; margin:auto; }

工作代码段(单击“扩展代码段”链接可全屏查看它,并查看排列的表列。)

.container {
    position: relative;
  margin-right: auto;
  margin-left: auto;
  padding-left: 15px;
  padding-right: 15px;
}

.table td,
.table th {
  width: 50%;
  padding-left: 10px;
  word-break: break-word;
}

.table { 
  max-width:1000px; 
  margin:auto; 
}
  
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

<div class="container">
            <h2><i class="fas fa-home"></i> Table x</h2>
        <table class="table">
          <thead>
            <tr>
              <th scope="col">Column 1</th>
              <th scope="col">Column 2</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis fringilla arcu id commodo.Etiam facilisis fringilla arcu id commodo.</td>
            </tr>
          </tbody>
        </table>
  <p>Suspendisse potenti. Sed eu dui at magna finibus vehicula. Suspendisse sagittis ipsum arcu. Quisque non elit et purus finibus vehicula. Vivamus faucibus tincidunt erat, sit amet auctor risus luctus nec. Nunc commodo tristique enim, et rhoncus</p>
    <h2><i class="fas fa-home"></i> Table y</h2>
    <table class="table">
          <thead>
            <tr>
              <th scope="col">Column 1</th>
              <th scope="col">Column 2</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisis</td>
            </tr>
            <tr>
              <th class="table-cell" scope="row">Etiam</th>
              <td>Etiam facilisisEtiam facilisisEtiam facilisis</td>
            </tr>
          </tbody>
        </table>
      </div>

<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何将HTML表td值放在同一行的新行中

来自分类Dev

如何将“表单”放在同一行中?

来自分类Dev

如何将元素与css放在一行中?

来自分类Dev

如何将今天的日期放在Python数据框的每一行的第一列中?

来自分类Dev

如何将tsv中的第一行放在表中的thead <th>行中,其余的如何用d3转到tbody <td>

来自分类Dev

如何将3个元素放在父div的一行中?

来自分类Dev

如何将Input和Icon放在同一行中实现?

来自分类Dev

如何将2个listView放在一行中?

来自分类Dev

如何将两个不同类型的输入放在一行中?

来自分类Dev

如何将分号放在富文本框中的同一行上?

来自分类Dev

如何将3个元素放在父div的一行中?

来自分类Dev

HTML / CSS:如何将<ul>中的所有<li>放在同一行并居中

来自分类Dev

如何将Input和Icon放在同一行中实现?

来自分类Dev

Excel VBA:如何将公式放在唯一行数的下一个可用列中?

来自分类Dev

如何将按钮和一些文本放在一行中,并使文本垂直对齐:中;?

来自分类Dev

如何将多个复选框与其标签一起放在一行中?

来自分类Dev

如何将两个带有边距的文本字段放在一行中?

来自分类Dev

当满足条件时,如何将表中特定列的每一行的长度与支持表中的特定值相面对,并创建一个Flag?

来自分类Dev

如何将数字从左到右放在一列中?

来自分类Dev

如何将一行移一列?

来自分类Dev

如何将一列转成一行?

来自分类Dev

如何将文本框放在表数据中,哪些行已从另一表追加/移动?

来自分类Dev

如何将文本框放在表数据中,哪些行已从另一表追加/移动?

来自分类Dev

如何将向量写入数据表同一行的几列中?

来自分类Dev

如何将当前行与php中mysql表的下一行进行比较

来自分类Dev

如何将列名存储为数据表中的第一行?

来自分类Dev

如何将Bootstrap 3孔放在同一行上?

来自分类Dev

如何将图像和输入与CSS放在同一行

来自分类Dev

如何将多个链接放在同一行上?(HTML5)

Related 相关文章

  1. 1

    如何将HTML表td值放在同一行的新行中

  2. 2

    如何将“表单”放在同一行中?

  3. 3

    如何将元素与css放在一行中?

  4. 4

    如何将今天的日期放在Python数据框的每一行的第一列中?

  5. 5

    如何将tsv中的第一行放在表中的thead <th>行中,其余的如何用d3转到tbody <td>

  6. 6

    如何将3个元素放在父div的一行中?

  7. 7

    如何将Input和Icon放在同一行中实现?

  8. 8

    如何将2个listView放在一行中?

  9. 9

    如何将两个不同类型的输入放在一行中?

  10. 10

    如何将分号放在富文本框中的同一行上?

  11. 11

    如何将3个元素放在父div的一行中?

  12. 12

    HTML / CSS:如何将<ul>中的所有<li>放在同一行并居中

  13. 13

    如何将Input和Icon放在同一行中实现?

  14. 14

    Excel VBA:如何将公式放在唯一行数的下一个可用列中?

  15. 15

    如何将按钮和一些文本放在一行中,并使文本垂直对齐:中;?

  16. 16

    如何将多个复选框与其标签一起放在一行中?

  17. 17

    如何将两个带有边距的文本字段放在一行中?

  18. 18

    当满足条件时,如何将表中特定列的每一行的长度与支持表中的特定值相面对,并创建一个Flag?

  19. 19

    如何将数字从左到右放在一列中?

  20. 20

    如何将一行移一列?

  21. 21

    如何将一列转成一行?

  22. 22

    如何将文本框放在表数据中,哪些行已从另一表追加/移动?

  23. 23

    如何将文本框放在表数据中,哪些行已从另一表追加/移动?

  24. 24

    如何将向量写入数据表同一行的几列中?

  25. 25

    如何将当前行与php中mysql表的下一行进行比较

  26. 26

    如何将列名存储为数据表中的第一行?

  27. 27

    如何将Bootstrap 3孔放在同一行上?

  28. 28

    如何将图像和输入与CSS放在同一行

  29. 29

    如何将多个链接放在同一行上?(HTML5)

热门标签

归档