Bootstrap 4-如何创建从第二列开始的表?

时间:2018-12-27 17:07:56

标签: html bootstrap-4

我确实有此HTML,但是我无法做到这一点:

  • 第一列width的{​​{1}}应该与Links available的长度相同,并且文本不应将这两个词分开。应该是一行Links available
  • Links available列上,仅标头很重要,下面的单元格将不被使用,因此可以将其隐藏
  • 按钮应该有Links available,并且应该像little bit space between next button ...

我想要的视觉效果

enter image description here

我的HTML:

inline

如果您想测试我的代码,请使用: codeply - Bootstrap snippets

2 个答案:

答案 0 :(得分:1)

如果要删除响应度列

更改

  

col-md-3

  

col-3

谢谢!

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet">

<table class="table">
    <thead>
        <tr class="">
            <th class="">Links available:</th>
            <th class="">Category 1</th>
            <th class="">Category 2</th>
            <th class="">Category 3</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td class=""></td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
        </tr>
        <tr>
            <td class=""></td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
        </tr>
        <tr>
            <td class=""></td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
            <td class="">
                <div class="row">
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                    <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
                </div>
            </td>
        </tr>
    </tbody>           
</table>

使用DIV的第二个代码

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet">

<div class="container-fluid p-0">
    <div class="row m-0">
        <div class="col-3 p-0">
            <p class="font-weight-bold">Links available:</p>
        </div>
        <div class="col-3 p-0">
            <p class="font-weight-bold">Category 1</p>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
        </div>
        <div class="col-3 p-0">
            <p class="font-weight-bold">Category 2</p>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
        </div>
        <div class="col-3 p-0">
            <p class="font-weight-bold">Category 3</p>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
            <button type="button" class="btn btn-outline-primary btn-sm col-md-3 mr-1">Small button</button>
        </div>
    </div>
</div>

答案 1 :(得分:0)

我认为您正在搜索嵌套的Grid Layout。我建议您阅读此书,以便您可以看到有关如何使用 Bootstrap Grid System 的示例。此外,在 XS (超小)屏幕尺寸上,由于可用宽度很小,我建议垂直堆叠类别。您可以在下一个示例中查看全部内容:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>

<div class="container-fluid">
<div class="row">

  <div class="col-sm-3 text-center">
    <p class="my-1">Links available:</p>
  </div>

  <div class="col-sm-3 text-center bg-warning">
    <div class="row">
      <div class="col-12 my-1">Category 1:</div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
    </div>
  </div>

  <div class="col-sm-3 text-center">
    <div class="row">
      <div class="col-12 my-1">Category 2:</div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
    </div>
  </div>

  <div class="col-sm-3 text-center bg-warning">
    <div class="row">
      <div class="col-12 my-1">Category 3:</div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-primary btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-danger btn-block">B</button>
      </div>
      <div class="col-4 my-1">
        <button type="button" class="btn btn-success btn-block">B</button>
      </div>
    </div>
  </div>

</div>
</div>