Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align div on the bottom inside table cell

Tags:

html

alignment

I want the content of the second div to be bottom-aligned with the image.

<table>
  <tr>
    <td>
      <div>
        <div style="float: left;">
          <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"  style="max-width: 200px; max-height: 200px;"/>
        </div>
        <div style="float: right; vertical-align: bottom;">
          I want this text be on the same line as the bottom of the image
        </div>
      </div>
    </td>
  </tr>
</table>
like image 567
Vitaly P Avatar asked Sep 21 '15 10:09

Vitaly P


2 Answers

You can do this with the table and table-cell display properties.

<table>
  <tr>
    <td>
      <div style="display:table">
        <div style="display:table-cell">
          <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"  style="max-width: 200px; max-height: 200px;"/>
        </div>
        <div style="vertical-align: bottom; display: table-cell">
          I want this text be on the same line as the bottom of the image
        </div>
      </div>
    </td>
  </tr>
</table>

Though I'd suggest you do the styling on a separate CSS file or embedding it, rather than adding it inline. Example:

.outer {
  display: table;
}

.inner {
  display: table-cell;
  vertical-align: bottom;
}
<table>
  <tr>
    <td>
      <div class="outer">
        <div>
          <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png"  style="max-width: 200px; max-height: 200px;"/>
        </div>
        <div class="inner">
          I want this text be on the same line as the bottom of the image
        </div>
      </div>
    </td>
  </tr>
</table>

If you want to have the text at the bottom, but also centered, you can add text-align: center.

like image 50
Chris Avatar answered Sep 17 '22 15:09

Chris


You can add display: table-cell to div elements inside table:

table tbody tr td div div {
  display: table-cell;
}
<table>
  <tr>
    <td>
      <div>
        <div>
          <img src="http://www.online-image-editor.com//styles/2014/images/example_image.png" style="max-width: 200px; max-height: 200px;" />
        </div>
        <div style="vertical-align: bottom;">
          I want this text be on the same line as the bottom of the image
        </div>
      </div>
    </td>
  </tr>
</table>
like image 43
Alex Char Avatar answered Sep 16 '22 15:09

Alex Char