Skip to content Skip to sidebar Skip to footer

How Can I Vertically Align An Image And Text To The Middle Within Divs

For example: http://jsfiddle.net/S23ut/1/ I would like the image and the text to be vertically align to the middle of its container. I can't seem to get the CSS right for this. Any

Solution 1:

I'm not sure about cross-browser compatibility, but using the CSS display: table-XXX might work:

#offer_widget.row {
    display: table-row;
}

#offer_widget.row_image {
    display: table-cell;
    text-align:center;
    vertical-align: middle;
}
#offer_widget.row_text {
    display: table-cell;
    vertical-align: middle;
}

See this update to your jsFiddle.

Solution 2:

hey remove float and give display table properties live demo http://jsfiddle.net/rohitazad/S23ut/5/

Solution 3:

Use below css styles in 2 nested divs:

display:table
display:table-cell

For example.

<html><head><style>#outer{width:100px; height:60px; border:solid 1px#f00;display:table;}
        #inner{display:table-cell; vertical-align:middle;text-align:center;font-size:16px;}
    </style></head><body><divid="outer"><divid="inner">test</div></div></body></html>

Post a Comment for "How Can I Vertically Align An Image And Text To The Middle Within Divs"