Hello
I am looking for the correct way to control the alignment of elements in my HTML page.
in the old days, I used to add the <center> tag whenever I wanted to center some content.
if I wanted to set the alignment of content inside a table cell, I would use <td align="left"> or <td align="center">
I also noticed the CSS rule text-align.
My question is, what is the correct way to use CSS to align elements so that it adhere with strict DTD rules
regardsyou can use float:left; or right...Look into the styles "text-align:center" and "margin:xxx auto" here (<!-- m --><a class="postlink" href="http://www.meyerweb.com/eric/css/references/css1ref.html">http://www.meyerweb.com/eric/css/refere ... s1ref.html</a><!-- m -->).Originally posted by ray326
Look into the styles "text-align:center" and "margin:xxx auto" here (<!-- m --><a class="postlink" href="http://www.meyerweb.com/eric/css/references/css1ref.html">http://www.meyerweb.com/eric/css/refere ... s1ref.html</a><!-- m -->). Which will make your whole layout centerd in the screen
heres an example <!-- m --><a class="postlink" href="http://doubleimage.net/faux.htmlThanks">http://doubleimage.net/faux.htmlThanks</a><!-- m --> for the replies
I have tried to use the correct HTML/CSS code to center a simple page like so:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
</head>
<body>
<div style="margin: 10px auto">
test
</div>
</body>
</html>
can you see what is going on wrong? The content gets displayed left aligned and not centeredYou need to specify a width for the div, else it will take up the available space. Here is the "suspenders and a belt" approach (center the div AND center the text within the div):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
</head>
<body>
<div style="width: 4em; text-align: center; margin: 10px auto">
test
</div>
</body>
</html>
I am looking for the correct way to control the alignment of elements in my HTML page.
in the old days, I used to add the <center> tag whenever I wanted to center some content.
if I wanted to set the alignment of content inside a table cell, I would use <td align="left"> or <td align="center">
I also noticed the CSS rule text-align.
My question is, what is the correct way to use CSS to align elements so that it adhere with strict DTD rules
regardsyou can use float:left; or right...Look into the styles "text-align:center" and "margin:xxx auto" here (<!-- m --><a class="postlink" href="http://www.meyerweb.com/eric/css/references/css1ref.html">http://www.meyerweb.com/eric/css/refere ... s1ref.html</a><!-- m -->).Originally posted by ray326
Look into the styles "text-align:center" and "margin:xxx auto" here (<!-- m --><a class="postlink" href="http://www.meyerweb.com/eric/css/references/css1ref.html">http://www.meyerweb.com/eric/css/refere ... s1ref.html</a><!-- m -->). Which will make your whole layout centerd in the screen
heres an example <!-- m --><a class="postlink" href="http://doubleimage.net/faux.htmlThanks">http://doubleimage.net/faux.htmlThanks</a><!-- m --> for the replies
I have tried to use the correct HTML/CSS code to center a simple page like so:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
</head>
<body>
<div style="margin: 10px auto">
test
</div>
</body>
</html>
can you see what is going on wrong? The content gets displayed left aligned and not centeredYou need to specify a width for the div, else it will take up the available space. Here is the "suspenders and a belt" approach (center the div AND center the text within the div):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
</head>
<body>
<div style="width: 4em; text-align: center; margin: 10px auto">
test
</div>
</body>
</html>