Jump to content

Vertical Center?


michaellunsford

Recommended Posts

okay, it's centering horizontally -- why isn't it centering vertically?

[code=php:0]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>untitled</title>
<style type="text/css">
html,body {
height:101%;
}
</style>
</head>
<body>
<div style="margin:auto; width:481px; height:327px;"><img src="images/splash.jpg" alt="" width="481" height="327" border="0"></div>
</body>
</html>
[/code]

I've even tried writing a specific "auto" to each margin type (ie, left, right, top bottom). I've also tried giving it a height of 100% and a vertical-align:middle without success. The only thing that does work is making a table 100% high, and valigning a 100% high TD. This really seems like the long way around, though.

What am I missing?
Link to comment
Share on other sites

[quote author=effigy link=topic=106885.msg428651#msg428651 date=1157483067]
You can try the negative margin trick:

[code]
div {
position: absolute;
top: 50%;
left: 50%;
height: 200px;
width: 600px;
margin: -100 -300;
text-align: center;

}
[/code]
[/quote]

Awesome! It works in both IE and Firefox.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.