Could anyone tell me how to get the <div> below to align in the centre of a page please? Thanks - I have looked all over the W3Schools CSS pages but cannot find out how to do what ought to be simple.
<div style="position:relative; top:0; left:0; overflow:hidden; background-color:#FFFFFF; width:85%; height:18%; border:1px solid #DEDEDE;"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
</head>
<body>
<div style="background-color:#fff; width:85%;; border:1px solid #ddd; margin:auto">Example</div>
</body>
</html>Thanks for your answer Charles. Which bit makes it go in the centre?margin:auto and having a width defined.Thanks again for answers. I have put this on a page:
<body>
<div style="background-color:#FFFFFF; width:55%; border:1px solid #000000; margin:auto">Example</div>
</body>
and it stubbornly appears aligned with the left of the page.That's because you're using invalid HTML. The following does, indeed, work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
</head>
<body>
<body>
<div style="background-color:#FFFFFF; width:55%; border:1px solid #000000; margin:auto">Example</div>
</body>
</body>
</html>Thanks Charles, you are, of course, correct. Is there any particular bit of what you posted that is likely to have caused yours to work and mine not to work.
I did not have:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
at the top of my page
and I did not have:
<html lang="en"> - I just had <html>
and I did not have:
<meta name="Content-Style-Type" content="text/css">
and instead of:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
I had:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
I tried substituting the various elements that you have into my page but nothing specific made any difference until everything was changed.Posting a link to your site will help us greatly as we can look through and find the problem. It also eliminates the guess work. Originally posted by Webskater
Thanks Charles, you are, of course, correct. Is there any particular bit of what you posted that is likely to have caused yours to work and mine not to work.
I did not have:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
at the top of my page
and I did not have:
<html lang="en"> - I just had <html>
and I did not have:
<meta name="Content-Style-Type" content="text/css">
and instead of:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
I had:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
I tried substituting the various elements that you have into my page but nothing specific made any difference until everything was changed. The HTML, HEAD and BODY tags are optional, the rest is required.
<div style="position:relative; top:0; left:0; overflow:hidden; background-color:#FFFFFF; width:85%; height:18%; border:1px solid #DEDEDE;"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
</head>
<body>
<div style="background-color:#fff; width:85%;; border:1px solid #ddd; margin:auto">Example</div>
</body>
</html>Thanks for your answer Charles. Which bit makes it go in the centre?margin:auto and having a width defined.Thanks again for answers. I have put this on a page:
<body>
<div style="background-color:#FFFFFF; width:55%; border:1px solid #000000; margin:auto">Example</div>
</body>
and it stubbornly appears aligned with the left of the page.That's because you're using invalid HTML. The following does, indeed, work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
</head>
<body>
<body>
<div style="background-color:#FFFFFF; width:55%; border:1px solid #000000; margin:auto">Example</div>
</body>
</body>
</html>Thanks Charles, you are, of course, correct. Is there any particular bit of what you posted that is likely to have caused yours to work and mine not to work.
I did not have:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
at the top of my page
and I did not have:
<html lang="en"> - I just had <html>
and I did not have:
<meta name="Content-Style-Type" content="text/css">
and instead of:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
I had:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
I tried substituting the various elements that you have into my page but nothing specific made any difference until everything was changed.Posting a link to your site will help us greatly as we can look through and find the problem. It also eliminates the guess work. Originally posted by Webskater
Thanks Charles, you are, of course, correct. Is there any particular bit of what you posted that is likely to have caused yours to work and mine not to work.
I did not have:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
at the top of my page
and I did not have:
<html lang="en"> - I just had <html>
and I did not have:
<meta name="Content-Style-Type" content="text/css">
and instead of:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
I had:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
I tried substituting the various elements that you have into my page but nothing specific made any difference until everything was changed. The HTML, HEAD and BODY tags are optional, the rest is required.