Click to See Complete Forum and Search --> : centering a <div> in all browsers and resolutions


myanavrin
09-05-2007, 08:34 AM
Hello to all,

How can I center <div> in all browsers and resolutions. Css or html.

Fang
09-05-2007, 08:54 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Basic center page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
html, body {
margin:0;
text-align:center;
}
#container {
margin:0 auto;
width:80%; /* change to required width */
text-align:left;
}
#contents { /* any element here is centered */
border:1px solid red;
}
</style>
</head>
<body>
<div id="container">
<div id="contents">
<p>contents</p>
</div>

</div>
</body>
</html>