Bootstrap table 没有响应
Boostrap table not responsive
我正在使用 bootstrap 做一个简单的网站。现在,里面有一些信息。
我确实在互联网上查看过如何让它响应,但到目前为止还没有。有人有 link 可以帮助我吗?
这是代码(有点长,不好意思)
<div class="container">
<div class="row justify-content-center" style="color:#002D59">
<div class="col-xl-7 col-lg-8 col-md-10 col-sm-12 mx-auto text-center p-4">
<div class="mt-3 mb-3 text-center">
<nav class="nav nav-tabs">
<a class="nav-item nav-link active " href="#test1" data-toggle="tab">Test 1 tab here</a>
<a class="nav-item nav-link" href="#test2" data-toggle="tab">Test 2</a>
<a class="nav-item nav-link" href="#test3" data-toggle="tab">Test 3 here hey</a>
<a class="nav-item nav-link" href="#test4" data-toggle="tab">im here test 4</a>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active" id="test1">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Date of creation</th>
<th scope="col">detail</th>
<th scope="col">state</th>
<th scope="col">comments</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>21/02/2020</td>
<td>
<div class="col-sm text-center">
<a class="btn btn-sm" href="#" role="button" style="background-color: #002D59; color: #FFFFFF; border-radius: 10px">
Link
</a>
</div>
</td>
<td>description here</td>
<td>comments over here</td>
</tr>
</tbody>
</table>
</div>
其他 3 人有相同的代码。
亲切
使用 table-responsive
class 使 table 响应。
您还可以使用一些 CSS 属性 来提高 table 的响应速度。
tr td {
word-break: break-all;
overflow-wrap: break-word;
max-width: 30rem;
}
在这里它给所有 td
到 max-width: 30rem
( 1rem = 16px ) 并允许在你的 table.
内容中打断单词
tr td:nth-child(2) {
min-width: 15rem !important;
}
设置 max-width
后所有 td
自动设置其宽度,但有时像 email field
或 description field
你需要更多宽度,所以你可以设置 min-width: 15rem
或 < 任何宽度 > 到特定 td
.
希望以上步骤对您有所帮助。
更新
要使 nav-tabs
响应,您可以使用 flexbox
。
这里我用了 flex-column flex-sm-row
两个 class 来让你的 nav-tabs
响应。
您可以在 https://getbootstrap.com/docs/4.4/utilities/flex/
查看那些 classes
工作示例
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="container">
<div class="row justify-content-center" style="color:#002D59">
<div class="col-xl-7 col-lg-8 col-md-10 col-sm-12 mx-auto text-center p-4">
<div class="mt-3 mb-3 text-center">
<nav class="nav nav-tabs flex-column flex-sm-row">
<a class="nav-item nav-link active " href="#test1" data-toggle="tab">Test 1 tab here</a>
<a class="nav-item nav-link" href="#test2" data-toggle="tab">Test 2</a>
<a class="nav-item nav-link" href="#test3" data-toggle="tab">Test 3 here hey</a>
<a class="nav-item nav-link" href="#test4" data-toggle="tab">im here test 4</a>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active" id="test1">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Date of creation</th>
<th scope="col">detail</th>
<th scope="col">state</th>
<th scope="col">comments</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>21/02/2020</td>
<td>
<div class="col-sm text-center">
<a class="btn btn-sm" href="#" role="button" style="background-color: #002D59; color: #FFFFFF; border-radius: 10px">Link</a>
</div>
</td>
<td>description here</td>
<td>comments over here</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
我正在使用 bootstrap 做一个简单的网站。现在,
我确实在互联网上查看过如何让它响应,但到目前为止还没有。有人有 link 可以帮助我吗?
这是代码(有点长,不好意思)
<div class="container">
<div class="row justify-content-center" style="color:#002D59">
<div class="col-xl-7 col-lg-8 col-md-10 col-sm-12 mx-auto text-center p-4">
<div class="mt-3 mb-3 text-center">
<nav class="nav nav-tabs">
<a class="nav-item nav-link active " href="#test1" data-toggle="tab">Test 1 tab here</a>
<a class="nav-item nav-link" href="#test2" data-toggle="tab">Test 2</a>
<a class="nav-item nav-link" href="#test3" data-toggle="tab">Test 3 here hey</a>
<a class="nav-item nav-link" href="#test4" data-toggle="tab">im here test 4</a>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active" id="test1">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Date of creation</th>
<th scope="col">detail</th>
<th scope="col">state</th>
<th scope="col">comments</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>21/02/2020</td>
<td>
<div class="col-sm text-center">
<a class="btn btn-sm" href="#" role="button" style="background-color: #002D59; color: #FFFFFF; border-radius: 10px">
Link
</a>
</div>
</td>
<td>description here</td>
<td>comments over here</td>
</tr>
</tbody>
</table>
</div>
其他 3 人有相同的代码。
亲切
使用 table-responsive
class 使 table 响应。
您还可以使用一些 CSS 属性 来提高 table 的响应速度。
tr td {
word-break: break-all;
overflow-wrap: break-word;
max-width: 30rem;
}
在这里它给所有 td
到 max-width: 30rem
( 1rem = 16px ) 并允许在你的 table.
tr td:nth-child(2) {
min-width: 15rem !important;
}
设置 max-width
后所有 td
自动设置其宽度,但有时像 email field
或 description field
你需要更多宽度,所以你可以设置 min-width: 15rem
或 < 任何宽度 > 到特定 td
.
希望以上步骤对您有所帮助。
更新
要使 nav-tabs
响应,您可以使用 flexbox
。
这里我用了 flex-column flex-sm-row
两个 class 来让你的 nav-tabs
响应。
您可以在 https://getbootstrap.com/docs/4.4/utilities/flex/
查看那些 classes工作示例
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="container">
<div class="row justify-content-center" style="color:#002D59">
<div class="col-xl-7 col-lg-8 col-md-10 col-sm-12 mx-auto text-center p-4">
<div class="mt-3 mb-3 text-center">
<nav class="nav nav-tabs flex-column flex-sm-row">
<a class="nav-item nav-link active " href="#test1" data-toggle="tab">Test 1 tab here</a>
<a class="nav-item nav-link" href="#test2" data-toggle="tab">Test 2</a>
<a class="nav-item nav-link" href="#test3" data-toggle="tab">Test 3 here hey</a>
<a class="nav-item nav-link" href="#test4" data-toggle="tab">im here test 4</a>
</nav>
<div class="tab-content">
<div class="tab-pane fade show active" id="test1">
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Date of creation</th>
<th scope="col">detail</th>
<th scope="col">state</th>
<th scope="col">comments</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>21/02/2020</td>
<td>
<div class="col-sm text-center">
<a class="btn btn-sm" href="#" role="button" style="background-color: #002D59; color: #FFFFFF; border-radius: 10px">Link</a>
</div>
</td>
<td>description here</td>
<td>comments over here</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>