maimok
maimok

Reputation: 373

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>

Upvotes: 12

Views: 37236

Answers (4)

Pavel Suk
Pavel Suk

Reputation: 41

For me is working to wrap table with

 <div class="card table-responsive border-0">

Upvotes: 0

Natty Mako
Natty Mako

Reputation: 1

<div class="table-responsive card rounded-3 p-0 m-0">
  <table class="table table-bordered table-striped rounded-3 border overflow-hidden p-0 m-0">
    <tr>
      <td></td>
    </tr>
    <table>
</div>

Upvotes: -1

sxzzz
sxzzz

Reputation: 149

Bootstrap has own class to use.

<table class="rounded-3 overflow-hidden"></table>

Upvotes: 14

Spectric
Spectric

Reputation: 31992

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>

Upvotes: 15

Related Questions