Zxian Posted January 21, 2007 Posted January 21, 2007 I'm wondering if anyone has any CSS-only methods of making a div of a fixed height appear vertically centered in the page. I've found methods that make it appear like this, but most of them use some sort of 25/50/25 rule (percentages here) to make the "middle section" appear in the center.Any ideas?
n7Epsilon Posted January 21, 2007 Posted January 21, 2007 How about something like this:.mydiv{ background-color: black; color: white; position: fixed; left: 10em; top: 10em; right: 10em; bottom: 10em; height: 100px;}To make its height fixed, i overrode the auto height adjustment with height: 100px. And if you change position to absolute instead of fixed, it will be like a normal div, else now it is fixed in the middle.
ripken204 Posted January 21, 2007 Posted January 21, 2007 you mean that this doesnt work?div.whatever { vertical-align: middle; }
Zxian Posted January 22, 2007 Author Posted January 22, 2007 @n7epsilon - thanks for the reply, but it doesn't seem to work for me in Opera or IE7. I had thought of something like that, but sending conflicting information about an object usually ends up with strange cross-browser performance.@ripken204 - nope... try it yourself.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now