Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zero width inline element moves justified text node contents

I have a justified text node into which I want to insert an inline placeholder ( element if you like) whose only content is a "‍" that shouldn't have any width (and chrome inspector says as much too). I have noticed that when I insert this node inline into the text node, the whole line "jiggles" as if recalculating the layout, although this should not affect it.

I have also tested that if the text node I insert it into is left-aligned, this slight movement does not happen. Is this just inherent to the way the browser calculates text placement in a justified text element or could there be any workaround for this?

like image 240
daaanipm Avatar asked Oct 02 '11 00:10

daaanipm


1 Answers

As I suspected, the issue, rather no issue, is due to the way "justify" works. First to confirm that "justify" text-align is causing this, check the jsffidle : http://jsfiddle.net/e7Ne2/29/

Both divs are same -> except that First div has text-align: justify and the other does not.

You will see that first div shows that behaviour but not second div.

This is because "justify" works this way (from wiki):

In justified text, the spaces between words, and, to a lesser extent, between glyphs or letters (kerning), are stretched or sometimes compressed in order to make the text align with both the left and right margins.

So, when we introduct a &zwb;, the text gets reorganized. This behaviour not consistent because not all characters are modified with &zwb;. So, when &zwb; alters the text, few letters "may be" stretched/compressed leading to the seemingly weird behaviour

like image 135
Lucky Murari Avatar answered Nov 14 '22 22:11

Lucky Murari