Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Table has huge space when is child of div flex

I’m trying to put an HTML table on the right side of a canvas and for some reason, it has huge spaces between rows.

I’ve tried the solution here
and here but none of them solved the problem.

Here’s my current code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<html>

<body style="margin: 0px">
  <div style="display: flex">
    <canvas style="background-color: blue;"></canvas>
    <table>
      <tbody>
        <tr>
          <td>hi</td>
          <td>l</td>
        </tr>
        <tr>
          <td>lol</td>
        </tr>
    </table>
  </div>
</body>

</html>

>Solution :

Solution 1 – Set align-items: flex-start in div because the default value is stretch

div {
  display: flex;
  align-items: flex-start;
}

canvas {
  background-color: blue;
}

table {
  border: 1px solid red;
}
<div>
  <canvas></canvas>
  <table>
    <tbody>
      <tr>
        <td>hi</td>
        <td>l</td>
      </tr>
      <tr>
        <td>lol</td>
      </tr>
  </table>
</div>

Solution 2 – Set align-self: flex-start in table

div {
  display: flex;
}

canvas {
  background-color: blue;
}

table {
  border: 1px solid red;
  align-self: flex-start
}
<div>
  <canvas></canvas>
  <table>
    <tbody>
      <tr>
        <td>hi</td>
        <td>l</td>
      </tr>
      <tr>
        <td>lol</td>
      </tr>
  </table>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading