Home > other >  remove gap between image and row-border
remove gap between image and row-border

Time:09-22

I have inserted an image in a table cell, and I want to have the row-height exactly the same height as the image. Now there seems to be a litle gap between the image and the row bottom- border. is there a way to remove this ?

<html>
<head>
    <title>TODO supply a title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
    table  {
      border : 2px solid brown;
      border-collapse: collapse;
      padding : 0px;
    }
    tr {
        border : 1px dotted darksalmon ;
        height : auto;
         }        
    img {
        width : 25px;
        height: 25px;
        border : 1px solid red; }
    </style>
</head>

<body>
    <div>TODO write content</div>
    <table  style="height: 0;">
        <tr>
            <td>
                cell 1
            </td>
            <td>
                cell 1
            </td>
        </tr>
        <tr style="height: 0;">
            <td>
                cell 1
            </td>
            <td>
                <img alt ="" src="APPROVED.jpg"/>
            </td>
        </tr>
        <tr>                
            <td>
                cell 1
            </td>
            <td>
                cell 1
            </td>
        </tr>
    </table>
</body>

output

CodePudding user response:

Try to use padding: 0 for td when your image places.

CodePudding user response:

you can use give padding value 0

if still can't, don't use hardcode

CodePudding user response:

Used flex property on td containing img so that image covers the height of container and added a padding: 0; to that class to remove any extra space

<html>

<head>
  <title>TODO supply a title</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <style>
    table {
      border: 2px solid brown;
      border-collapse: collapse;
      padding: 0px;
    }
    
    tr {
      border: 1px dotted darksalmon;
      height: auto;
    }
    
    img {
      width: 25px;
      height: 25px;
      border: 1px solid red;
    }
    
    .cover {
      display: flex;
      padding:0;
    }
  </style>
</head>

<body>
  <div>TODO write content</div>
  <table style="height: 0;">
    <tr>
      <td>
        cell 1
      </td>
      <td>
        cell 1
      </td>
    </tr>
    <tr style="height: 0;">
      <td>
        cell 1
      </td>
      <td class="cover">
        <img alt="" src="https://www.hdnicewallpapers.com/Walls/Big/Rainbow/Rainbow_on_Mountain_HD_Image.jpg" />
      </td>
    </tr>
    <tr>
      <td>
        cell 1
      </td>
      <td>
        cell 1
      </td>
    </tr>
  </table>
</body>

</html>

  • Related