Pains of vertical alignment in CSS

27 May 2009

Vertical alignment in CSS was being a pain, and I spent a while searching as I wanted to align something vertically to the bottom of an element.

I then came across a forum post with an intruiging method of doing it.

If I had this HTML code:

<div id="container"> <div id="verticallyaligned"> Contents </div> </div>

Then this CSS code would align it to the bottom:


#container {
position: relative;
width: 200px;
height: 200px;
border: solid 1px black;
padding: 0;
}
#verticallyaligned {
position: absolute;
bottom: 0;
width: 200px;
margin: 0;
}

A pretty nice find. I just wish you didn't have to refer to these funny 'quirks' all the time, and something like vertical-align would work in more situations.

 

Comments

Nobody has commented on this post yet.

Add comment

If you wish, you can add a comment.