htmlcsstwitter-bootstrap

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/bootstrap@5.0.0-beta1/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>


Solution

  • 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/bootstrap@5.0.0-beta1/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>