Jump to content

[HTML/CSS] - Vertical centering


Recommended Posts

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?

Link to comment
Share on other sites


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.

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...