Is there a way to center a div without using text-align?http://forums.webdeveloper.com/showthread.php?s=&threadid=30301&perpage=15&pagenumber=2#post162379#perimeter {
margin:0 auto;
}
I tried this, but nothing. And I tried this in the body too...Perhaps I should've been a bit more descriptive — you won't actually see the effect in action until you give the element in question an explicit width.<!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">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
<style type="text/css">
/*<![CDATA[*/
.center {
margin: 0 auto;
background: #eee;
color: #000;
padding: 5px;
border: solid #aaa 1px;
width: 90%;
}
/*]]>*/
</style>
</head>
<body>
<div class="center">I'm a centered element.</div>
</body>
</html>Sorry, in my source I have a width, but I just put that on the board...
Here is everything I have, and it still wont work... You can see my page here MY SITE (<!-- m --><a class="postlink" href="http://accessjdm.com/gsc/">http://accessjdm.com/gsc/</a><!-- m -->)
#perimeter {
border-left:2px solid #FFFF00;
border-right:2px solid #FFFF00;
height:100%;
margin:0 auto;
padding:0;
width:765px;
}I assume you're running IE6 which is actually in quirks mode disallowing your CSS to work correctly. You'll have to use a DOCTYPE to kick the browser in to what's known as "standards-compliance mode" or "strict mode". An HTML 4.01 or XHTML DOCTYPE will suffice. Try adding this at the top of your pages:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">Hey it worked! but everything else is messed up now... ?That's likely due to your use of invalid markup. Try validating your pages (<!-- m --><a class="postlink" href="http://validator.w3.org/">http://validator.w3.org/</a><!-- m -->) — after you correct the syntax errors listed, everything should be fine.
margin:0 auto;
}
I tried this, but nothing. And I tried this in the body too...Perhaps I should've been a bit more descriptive — you won't actually see the effect in action until you give the element in question an explicit width.<!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">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
<style type="text/css">
/*<![CDATA[*/
.center {
margin: 0 auto;
background: #eee;
color: #000;
padding: 5px;
border: solid #aaa 1px;
width: 90%;
}
/*]]>*/
</style>
</head>
<body>
<div class="center">I'm a centered element.</div>
</body>
</html>Sorry, in my source I have a width, but I just put that on the board...
Here is everything I have, and it still wont work... You can see my page here MY SITE (<!-- m --><a class="postlink" href="http://accessjdm.com/gsc/">http://accessjdm.com/gsc/</a><!-- m -->)
#perimeter {
border-left:2px solid #FFFF00;
border-right:2px solid #FFFF00;
height:100%;
margin:0 auto;
padding:0;
width:765px;
}I assume you're running IE6 which is actually in quirks mode disallowing your CSS to work correctly. You'll have to use a DOCTYPE to kick the browser in to what's known as "standards-compliance mode" or "strict mode". An HTML 4.01 or XHTML DOCTYPE will suffice. Try adding this at the top of your pages:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">Hey it worked! but everything else is messed up now... ?That's likely due to your use of invalid markup. Try validating your pages (<!-- m --><a class="postlink" href="http://validator.w3.org/">http://validator.w3.org/</a><!-- m -->) — after you correct the syntax errors listed, everything should be fine.