View Full Version : Code for centering
Mattgt
02-18-2007, 04:42 AM
any one no the html code that centers my website in any browser safri,ff,ie , ex....
tech_support
02-18-2007, 04:48 AM
<div align="center">
jlhaslip
02-18-2007, 06:42 AM
The code listed above will centre only the div it styles. This code will centre the entire site. Be sure to "uncentre" those things you want left justified.
<!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" xml:lang="en" lang="en">
<head>
<title>An XHTML 1.0 Strict standard template</title>
<meta http-equiv="content-type"
content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<style type="text/css">
body { margin: 0 auto; /* for modern browsers */
text-align:center; /* for older browsers */
}
</style>
</head>
<body>
<div>... site code here
<p>... Your HTML content here ...</p>
<p>
<a href="http://validator.w3.org/">validate the xhtml</a>
</p></div>
</body>
</html>
tech_support
02-18-2007, 08:37 AM
IE supports XHTML really badly.
http://www.hixie.ch/advocacy/xhtml
jscheuer1
02-18-2007, 09:10 AM
Styling the body like so:
<style type="text/css">
body { margin: 0 auto; /* for modern browsers */
text-align:center; /* for older browsers */
}
</style>
Can lead to more problems in a complex layout than will using a wrapper division:
<style type="text/css">
#wrapper { margin: 0 auto; /* for modern browsers */
text-align:center; /* for older browsers */
}
</style>
<body><div id="wrapper">
Your markup here
</div></body>
Also, text-align:center can have unexpected consequences, especially if absolute positioning is used within the content of an element so styled.
mburt
02-18-2007, 09:46 PM
Is the align attribute depreciated for <p>?
codeexploiter
02-19-2007, 03:31 AM
Is the align attribute depreciated for <p>?
Yes it is. You can have a look at this page (http://www.w3.org/TR/html401/present/graphics.html#h-15.1.2)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.