W3C home > Mailing lists > Public > www-style@w3.org > September 2001

vertical centering with CSS2

From: Nolan Clark <nolanc@ischool.washington.edu>
Date: Fri, 31 Aug 2001 20:56:30 -0400 (EDT)
Message-ID: <AACA31416CB5764DA77546B31532C5A7097162@fileserv.ischool.washington.edu>
To: "'www-style@w3.org'" <www-style@w3.org>
I have been unable to figure out how to "vertically center" things using
CSS2. To illustrate what I mean, consider the following:
 
<div style="width:300">
            <div style="width:20%; margin-left:auto;
margin-right:auto">text</div>
</div>
 
That centers the inner div horizontally, but what if I want to center it
vertically? The spec states that for absolutely positioned block level
elements, "margin + padding + height = container height", but it makes no
such requirements on normal, statically positioned blocks. Is there a
different way to do this?
 
Thanks for any help you can give me,
Nolan Clark
 
 
Received on Monday, 3 September 2001 10:45:38 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 27 April 2009 13:54:10 GMT