I am using bootstrap in my html thymeleaf template as follows:
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-KyZXEAg3QhqLMpG8r 8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We"
crossorigin="anonymous">
<table class="table table-striped table-sm" >
<thead>
<th>delete</th>
<th>Edit</th>
<th>Consult Date</th>
<th>Reservation Number</th>
<th>dispense details</th>
The table is stretched the width of my screen. How do I make table use 50-60% of the screen width?
CodePudding user response:
Utilize the BS grid and place the table inside a column. There are 12 columns in the grid so for 50-60% of the screen width use .col-6
(6/12 = 50%), .col-7
(7/12 = 58.333%) or one of their responsive variants.
In the following example, I use .col-sm-7
so it will take up all 12 columns on extra small screens and then only 7 columns on small and larger screens.
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r 8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="col-sm-7">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>delete</th>
<th>Edit</th>
<th>Consult Date</th>
<th>Reservation Number</th>
<th>dispense details</th>
</tr>
</thead>
<tbody>
<tr>
<td>yup</td>
<td>yup</td>
<td>yup</td>
<td>yup</td>
<td>yup</td>
</tr>
<tr>
<td>yup</td>
<td>yup</td>
<td>yup</td>
<td>yup</td>
<td>yup</td>
</tr>
<tr>
<td>yup</td>
<td>yup</td>
<td>yup</td>
<td>yup</td>
<td>yup</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>