Vincent <vi************@wanadoo.fr> wrote:
I am new to CSS (and web technologies in general) and trying to do some
basic stuff with it. For example, I'd like to position a block element
centered in a page: the text inside this block should be also centered.
Here is what I tried:
<html>
<head>
No Doctype so you're putting IE6 into quirks mode.
<style type="text/css">
<!--
body, ul, div {
margin: 0 ;
padding: 0 ;
}
.test {
text-align: center ;
width: 95% ;
margin: 1em auto ;
If you're setting the width to 95% why not use
margin: 1em 2.5%;
It's supported by a wider range of browsers than the auto value.
border: #3333ff 1px solid ;
}
-->
</style>
</head>
<body>
<div class="test">test</div>
</body>
</html>
In Mozilla, what I get is a blue rectangle around the div that's 95%
wide as the body, with some space left and right (presumably 2.5% each
side), plus text centered in this rectangle. Exactly what I want.
In IE6, the div pushed to left side, i.e. it's not centered at all. The
strange thing (to me) is that if I replace the div by an ul, then I get
what I want. Can you explain that ?
Actually, not the case. The UL is not centered, the standard left
indent makes it look as if it is. If you put both the div and the ul
in the same page you'll see that they end at the same point. i.e. the
95% includes the ul's left indent.
Have a look at the source of
http://steve.pugh.net/test/test58-s.html (standards mode)
and
http://steve.pugh.net/test/test58-s.html (quirks mode)
Steve
--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor
Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>