0

My template :

<td class="image">
    <img src="">
    <div class="align-bottom">
        text
    </div>
</td>
<td class="image">
    <img src="">
    <div class="align-bottom">
        text
    </div>
</td>
<td class="image">
    <img src="">
    <div class="align-bottom">
        text
    </div>
</td>

How do I vertical-middle align the image (the images have different sizes...) and vertical-bottom align the text(different sizes.)

The td height is dynamic.

I'm sorry but position:absolute doesn't work ...the images have different sizes.

LoveFortyDown
  • 1,011
  • 2
  • 17
  • 37
Michael Phelps
  • 3,451
  • 7
  • 36
  • 64

2 Answers2

2

What you can do is to have 2 rows in the table. Row 1 with all the images and Row 2 with the text

for each image add

img {    
  margin:auto;
}

and for text, align:center.

I think that should do the job.

Use this structure : http://jsfiddle.net/vse8cq5y/

Manmeet S. Oberoi
  • 1,082
  • 1
  • 17
  • 29
1

From your given HTML and request I'm assuming this is what you will need to get what you want.

The images should automatically do what you are asking, all you need to do is position absolute the text to the bottom of the td.

By adding padding bottom to the each td, you are allowing space for the text to go, meaning that it will never overlap with your image (regardless of image size).

img {
  background-color: red;
  display: block;
  width:5em;
  height:2em;
  margin: 0 auto;
}

td {
  width:10em;
  padding-bottom: 1em;
  position: relative;
  vertical-align: middle; /*should be default*/
}
.container {
  background-color: blue;
  display:inline-block;
}

.align-bottom {
  position: absolute;
  bottom: 0;
  left:0;
  display: inline;
  width: 100%;
  text-align: center;
}
<table>
<tr>
<td class="image">
        <img src="" style="height: 4em">
        <div class="align-bottom">
            text
        </div>
</td>
    <td class="image">
        <img src="" style="height: 7em">
        <div class="align-bottom">
            text
        </div>
</td>
<td class="image">
        <img src="" style="height: 10em">
        <div class="align-bottom">
            text
        </div>
</td>
</tr>
</table>
Tommy Jinks
  • 747
  • 6
  • 21
  • If the text is a lot of it will be in the picture – Michael Phelps Mar 06 '15 at 13:43
  • Either set your text to have a background color, however this will cut your image off. Another option will be to check for the height of your text, then supply this value to the padding-bottom of each td (this will need to be done using JavaScript or jQuery). – Tommy Jinks Mar 06 '15 at 14:05