Wrap columns in a table if the width overflows the container

I would like to create a responsive HTML table that wraps columns below itself if the width of the table overflows the container. It should look like this:

Default table design

And when it’s wrapped it schould look like this:

enter image description here

What is the optimal solution to this problem and can it be solved without using javascript?

The table in the default appearance is here:

table {
    width: 100%;
    border-spacing: 0;
    border-collapse: collapse;
}

table th,
table td {
    border-top: 1px solid #edf2f9;
    border-bottom: 1px solid #edf2f9;
    padding: 10px;
    text-align: left;
}

table th {
    background: #f9fbfd;
    font-size: 10pt;
    text-transform: uppercase;
    font-weight: 400;
}
<table>
  <thead>
    <tr>
      <th>First column</th>
      <th>Second column</th>
      <th>Third column</th>
      <th>Fourth column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>First column data 1</td>
      <td>Second column data 1</td>
      <td>Third column data 1</td>
      <td>Fourth column data 1</td>
    </tr>
    <tr>
      <td>First column data 2</td>
      <td>Second column data 2</td>
      <td>Third column data 2</td>
      <td>Fourth column data 2</td>
    </tr>
    <tr>
      <td>First column data 3</td>
      <td>Second column data 3</td>
      <td>Third column data 3</td>
      <td>Fourth column data 3</td>
    </tr>
  </tbody>
</table>

160 thoughts on “Wrap columns in a table if the width overflows the container”

  1. Pingback: sildenafil 50 mg
  2. Pingback: viagra
  3. Pingback: viagra pill
  4. Pingback: sildenafil 20mg
  5. Pingback: viagragates
  6. Pingback: 20mg cialis daily
  7. Pingback: cheap viagra
  8. Pingback: sildenafil online
  9. Pingback: viagra samples
  10. Pingback: cialis 20mg
  11. Pingback: cialis coupon
  12. Pingback: sildenafil generic
  13. Pingback: viagra pills
  14. Pingback: viagra gum
  15. Pingback: viagra tablet
  16. Pingback: viagra cvs
  17. Pingback: viagra history
  18. Pingback: viagra dosage
  19. Pingback: viagra connect
  20. Pingback: viagra generic
  21. Pingback: otc viagra
  22. Pingback: cialis viagra
  23. Pingback: walgreens viagra

Leave a Comment