An image placement problem to watch out for in Google Chrome

March 22, 2012

Google Chrome has an interesting little thing that it does, where it decides how the page will be laid out before it knows the dimensions of all the elements. For example, if you create a <div> tag with a large image in it, Chrome will calculate the height of the div before the image has loaded. That’s right - it figures out the height of the image’s container without necessarily knowing the size of the image.

So who cares? What does this mean?

Well, if you have elements styled as position: absolute in your page, you might find that they start out correctly placed, but they don’t move with the rest of the page when the image loads. This means that you have badly placed images sitting around in your page, making the whole thing a horrible mess.

Alternatively, you might have a set of images that are meant to sit in a nice little row inside a <div>, but they end up wrapping onto an extra line because Chrome didn’t wait until they’d loaded before it figured out how wide to make the <div>.

And what can you do about it? Here are a couple of options:

Hopefully this helps you figure out a problem some time. If not, just remember it was here.

An image placement problem to watch out for in Google Chrome - March 22, 2012 - Lucas Wilson-Richter