Re: Block alignment problem clarification

> Consider this structure:
> 
> <div id="parentDiv" style="text-align: center; width: 100%">
> <div id="childDiv" style="width: 50%">
> Div Contents here.
> </div>
> </div>
> 
> I've read the specification, and it says that when
> "text-align: center" is specified, all _inline_ content is aligned
> accordingly.  However, it doesn't say what happens to block
> elements. 

If it doesn't say anything, nothing happens.

Text-align affects the position of text within line boxes. It does not
affect the position of line boxes, the flow of elements, or anything
else. For example, assuming that text wrapping results in the following
text in a line box, text-align would determine how it was aligned within
said line box:

the words of a sentence.

Given text-align: left, the text that has been determined as being in
that line box would be displayed thus:
+-----------------------------------+
|the words of a sentence.           |
+-----------------------------------+
Given right:
+-----------------------------------+
|           the words of a sentence.|
+-----------------------------------+
Given center:
+-----------------------------------+
|     the words of a sentence.      |
+-----------------------------------+
Given justify:
+-----------------------------------+
|the words of a sentence.           |
+-----------------------------------+
(since text is not justified unless it fills more than one line box.

Note how text-align only affects alignment, not anything else.


> Now, IE 5.5 would align "childDiv" in the middle of the
> page (it's half the parentDiv, so the alignment would be
> 25%-50%-25%). 

No that would be margins. Margins are what affect the position of block
elements. To centre a block, you would specify margin-left: auto;
margin-right: auto.

> If Mozilla doesn't handle this as it should, it would be great if
> you let this be known on the above bugzilla page. 

Can't be bothered, sorry.

> If it does, then
> it's Explorer's glitch and should be handled by Microsoft.

Indeed. Although I think this is probably deliberate user-friendly
behaviour, in the same way that it allows text-align: center to affect
the position of tables.

Received on Tuesday, 11 April 2000 13:59:07 UTC