mlse
05-24-2005, 10:22 AM
Hi.
I have a small problem (for which I have looked at the FAQ in the pinned topics!), but which is, nevertheless, driving me crackers! :eek:
What I want to do is idiotically simple - to display a piece of text slap bang in the middle of a page (so that the margins top, bottom, left and right are equal). According to my book on CSS (and I quote from the book):
"margin-top, margin-right, margin-bottom, margin-left, margin
Values: auto, <length>, <percentage>
Description: Sets the size of margins around any given element ... If 'auto' is used for two opposing sides, then the margins on these opposing sides will be equal."
Ok. So I wrote the following, simple bit of HTML to test it ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Margin Test</title>
</head>
<body>
<div style="
width:100%;
height:100%;
background:red">
<div style="
margin:auto auto auto auto;
color:white;
font-family:arial;
font-size:30">
MIDDLE
</div>
</div>
</body>
</html>
I was (perhaps naively) under the impression (given the quoted description of margin), that this would cause the word "MIDDLE" to be displayed always in the middle of the page, no matter what it's size. It is, however, displayed in the top-left corner! (i.e. the web browser seems to ignore the "margin: auto auto auto auto" bit of the inner div!).
If someone could tell me what I'm doing wrong I would much appreciate it, because as far as I can tell, I've exactly logically followed the definition of margin that I quoted!
TIA,
Mike
I have a small problem (for which I have looked at the FAQ in the pinned topics!), but which is, nevertheless, driving me crackers! :eek:
What I want to do is idiotically simple - to display a piece of text slap bang in the middle of a page (so that the margins top, bottom, left and right are equal). According to my book on CSS (and I quote from the book):
"margin-top, margin-right, margin-bottom, margin-left, margin
Values: auto, <length>, <percentage>
Description: Sets the size of margins around any given element ... If 'auto' is used for two opposing sides, then the margins on these opposing sides will be equal."
Ok. So I wrote the following, simple bit of HTML to test it ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Margin Test</title>
</head>
<body>
<div style="
width:100%;
height:100%;
background:red">
<div style="
margin:auto auto auto auto;
color:white;
font-family:arial;
font-size:30">
MIDDLE
</div>
</div>
</body>
</html>
I was (perhaps naively) under the impression (given the quoted description of margin), that this would cause the word "MIDDLE" to be displayed always in the middle of the page, no matter what it's size. It is, however, displayed in the top-left corner! (i.e. the web browser seems to ignore the "margin: auto auto auto auto" bit of the inner div!).
If someone could tell me what I'm doing wrong I would much appreciate it, because as far as I can tell, I've exactly logically followed the definition of margin that I quoted!
TIA,
Mike