Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying border-radius to bootstrap 5 table

I am attempting to add a border-radius to my bootstrap 5 table.... I've done some research and many of the solutions say to wrap the table in a div and apply the border-radius to that div. I've attempted to do that but the border-radius has no effect on my table. I've also tried adding the border-radius class to the table but it still has no effect on the table.

I've applied the same css classes to the a div and the border-radius property is applied as expected.

How can I apply the border-radius to my bootstrap table?

Here is a code snippet:

.tbl-container { width: 400px; margin-top: 10px; margin-left: 10px;}

.bg-red {background-color:red; color:white;}

.bdr {border-radius: 6px;}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>



<div class="tbl-container bdr">
<table class="table bdr">
  <thead class="bg-red">
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>

</div>


<div class="tbl-container">
 <div class="bg-red bdr">
 TESTING BORDER
 </div>
</div>
like image 344
maimok Avatar asked Dec 18 '20 02:12

maimok


People also ask

How do I add a border radius to a table tr?

To add border radius to a table row tr , you have to specifically target the first table data td on the row and the last. This Pen is owned by Temitope Ayodele on CodePen.


2 Answers

The border radius is being applied on the parent div - it's just overflowing.

Apply overflow:hidden to the table parent:

.tbl-container {
  width: 400px;
  margin-top: 10px;
  margin-left: 10px;
}

.bg-red {
  background-color: red;
  color: white;
}

.bdr {
  border-radius: 6px;
  overflow: hidden;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />



<div class="tbl-container bdr"> <!-- <== overflow: hidden applied to parent -->
  <table class="table">
    <thead class="bg-red">
      <tr>
        <th scope="col">#</th>
        <th scope="col">First</th>
        <th scope="col">Last</th>
        <th scope="col">Handle</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">1</th>
        <td>Mark</td>
        <td>Otto</td>
        <td>@mdo</td>
      </tr>
      <tr>
        <th scope="row">2</th>
        <td>Jacob</td>
        <td>Thornton</td>
        <td>@fat</td>
      </tr>
      <tr>
        <th scope="row">3</th>
        <td>Larry</td>
        <td>the Bird</td>
        <td>@twitter</td>
      </tr>
    </tbody>
  </table>

</div>
like image 186
Spectric Avatar answered Oct 20 '22 02:10

Spectric


Bootstrap has own class to use.

<table class="rounded rounded-3 overflow-hidden "></table>
like image 1
sxzzz Avatar answered Oct 20 '22 03:10

sxzzz