Forum Moderators: open
There is a div with a fixed width full of a considerable amount of text. There is no left or right padding or border specified. With a slow connection I can see that the div is initially correctly sized, but as more and more text gets loaded the div suddenly widens by a few pixels - probably no more than 2 or 3.
From experimenting with other pages, I know this is due to a line of text fitting exactly within the width of the div before wrapping to the next line. If I change the word order so that the line wraps before it reaches the right-hand side of the div, the div does not expand.
Presume this is due to a miscalculation in IE6. Has anyone seen this before? And can anything be done about it?
IE also will sometimes add an extra line break, even if the next line doesn't print even one letter.
It's generally not a good idea to try for such tight control of a layout, cross-browser headaches are almost guaranteed. This kind of control is a print ideal, but not very well suited to the web. Line breaks simply will occur in different spots at times, even with the same browser but a different OS.
Thanks for the reply. My question was really an academic one because I always leave room for divs to expand or contract, mainly because of the different ways padding is handled. Nor am I trying to force any kind of layout. I merely provide a div with some text inside it and I expect it to wrap in different places depending on browser or how the user has set the font sizes. However I would expect the width of the div to stay stable, and the height (which is unspecified) to expand according to the amount of text. What I didn't expect to see is the width of the div changing.
I am interested that you say that expanding divs is permissable according to the W3C, but I always thought that was so they could accomodate contents larger than expected. In this case I don't see why any browser needs to increase the width, and in fact it is only IE that does.
Presumably when rendering text a browser has to calculate ahead to see if the next word will fit in the line, and if not wrap to the next line. It appears to me that IE's calculations are inaccurate. It renders the width of the div, then it starts rendering the text within that width,
but when it comes to a word that is a few pixels too wide for the remaining space, IE forces it in rather than wrapping it, and therefore resizes the div.
Sounds like a bug to me.
Harry
I think I've only seen it in quirks mode - are you using a full DTD and looking at the issue in standards mode when you run into it?
My guess is that in calculating font widths, small errors have a cumulative effect at the end of the line making IE think there is more space left than their actually is. But that's just a guess.
If you like I could sticky you the page. The effect is quite noticeable.