Today I have had a problem with hiding text with text-indent: -9999px rule. I realized that it was caused by some parent element which has had text-align: right. Example on jsfiddle. Setting text-indent to positive value of 9999px did not work as well.
I have managed to hide text by setting it’s text-align to the left, but I do not understand why such problem occurred.
Could someone explain why text-indenting does not work while text-align is set to the right?
Fiddle with ids:
http://jsfiddle.net/sNbfv/2/
It seems that maintaining the alignment is more important to the browser, so the right edge of the text is kept to the right side, no matter what.
The document is set to the
ltrdirection, so the indent is applied to the left of the line, but since you’ve said you want it to align to the right, the browser disregards the indent entirely. I have no explanation as to why this happens, other than early browsers setting a precedence of justification importance. There is nothing in the CSS spec as far astext-alignexplicitly ignoringtext-indent.http://www.w3.org/TR/CSS2/text.html#propdef-text-indent
If we update the fiddle to have an
rtldirection, the indent indeed affects the right side of the text. I’ve added a border to show that the overflow is happening.http://jsfiddle.net/sNbfv/3/
The simple solution seems to be aligning that nested indent
to text-align:left.http://jsfiddle.net/sNbfv/4/