Forum Bugs

text-align right bug

jccameron
Quick question. The following code in Prince:

<div style="width: 50px; border: 1px solid black">
	<div style="width: 100px">hello_there</div>
	<div style="width: 0px; text-align: right">hello_there</div>
</div>


has the second line outside of the box and to the left (basically an overflow to the left). Most browsers (all that I have tested) limit the starting point to the left edge of the container (since no negative elements have been applied).

Is this a bug or have you elected to use overflow to the left in a block where text-align right is in use?
mikeday
It does seem that Prince is giving the right alignment higher priority than the browsers do in this situation, where the width of the block is too narrow to contain the entire text. Whether it's a bug or not depends upon the CSS specification:
In general, the left edge of a line box touches the left edge of its containing block and the right edge touches the right edge of its containing block.
...
When the total width of the inline boxes on a line is less than the width of the line box containing them, their horizontal distribution within the line box is determined by the 'text-align' property.
...
When an inline box exceeds the width of a line box, [and cannot be split], then the inline box overflows the line box.

The first and third sentences leave it ambiguous, as the overflow could be in either direction, or determined by the text-align property. But the second sentence would seem to imply that the text-align property should be ignored altogether in cases where the inline boxes are wider than the line itself. So that supports the browsers' interpretation. I'll add this to the roadmap for further investigation.
jccameron
That is how I read it as well. And, during actual implementation, it seems counter-intuitive for it to overflow the left as it makes it nearly impossible to use text-align right in a variety of circumstances. Whereas most times you are okay with overflow down and to the right, the negative margin effect with this is hard to work-around.

Thanks for the quick reply!
mikeday
In Prince 7.0 we have changed text-align behaviour to be consistent with web browsers.