...

View Full Version : How to center a div ?



bulldorc
11-12-2010, 03:21 PM
Hi

I am a PHP coder and not very good at CSS. I wonder if there is away to center a div without using table or center tags ?:rolleyes:

Thanks.

*******
Tingoc (http://www.tingoc.com)

Chris Hick
11-12-2010, 03:50 PM
Put this within your div tags..




margin: 0 auto;
width: #; /* replace the # with a proper value. */

Excavator
11-12-2010, 03:51 PM
Hello bulldorc,
To center an element you need three things:

a valid DocType
an element with a width
that elements left/right margins set to auto


Here's a simple example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {background: #FC6;}
#container {
height: 400px;
width: 800px;
margin: 30px auto;
background: #999;
}
</style>
</head>
<body>
<div id="container">
<!--end container--></div>
</body>
</html>

bulldorc
11-12-2010, 04:56 PM
Great. Thank you both for quick responses

Chris Hick
11-14-2010, 07:15 PM
Don't forget to placed this as resolved. :thumbsup:

Steps:
edit opening post>go advanced>set the prefix before the title as resolved



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum