Reputation: 109
I'm doing a simple website using bootstrap. Right now, in which some information is inside.
I did check on the internet to see how to make this responsive, but so far nothing. Do someone have a link which can help me ?
Here is the code (which is a big long, sorry)
<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>
The 3 others have the same code.
Cordially
Upvotes: 1
Views: 368
Reputation: 19692
Use table-responsive
class to make a table responsive.
You can also use some CSS property to make table more responsive.
tr td {
word-break: break-all;
overflow-wrap: break-word;
max-width: 30rem;
}
Here it give all td
to max-width: 30rem
( 1rem = 16px ) and allow to break word in content of your table.
tr td:nth-child(2) {
min-width: 15rem !important;
}
after setting max-width
all td
automatically set its width but sometimes like in email field
or description field
you need more width so, you can set min-width: 15rem
OR < any width > to specific td
.
I hope the above steps will help you.
UPDATE
For making nav-tabs
responsive you can use flexbox
.
Here I used flex-column flex-sm-row
two classes to make your nav-tabs
responsive.
You can check those classes at https://getbootstrap.com/docs/4.4/utilities/flex/
WORKING EXAMPLE
<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/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
Upvotes: 1