I’m basically trying to achieve a group of divs each containing a left floated image with a nested div containing text that sits on the right hand side of the floated image. I have used inline-block as each group of divs will have varying heights, so wanted to have them wrapping nicely.
From what I have narrowed down, the image within .inline-blockElement is causing issues in Mozilla/netscape as it is stretching to the height of .inline-blockElement, and it’s also doubling the margin in .blockElement. (fyi - It appears every other browser is rendering ok.)
Is there a work-around or a better way of getting the inline-block to behave?
It’s also as a rule of thumb a really bad idea to try and use inline-block on block-level tags… since that can cause all sorts of headaches in IE – even modern versions which allegedly support that. I’d also be questioning the use of inline-block on them altogether as why aren’t you just floating the parent containers? You can’t even predict that 47% will always account for the space character between them. Some names on the elements that say what they are for CONTENT instead of just 'this is a block" – really? A div is a block? Who’d have thunk it?!? wouldn’t hurt either. Also, since you’re working inside a fixed width container, this should be a no-brainer.
admittedly there’s the right side padding issue, but that’s why generally I’d not have them flush against the left anyways. (or I’d use alternating classes)
If Ie6 and 7 support was needed then its just a matter of a couple of little hacks.
.inline-blockElement {
width:47%;
margin: 20px 20px 20px 0;
display: -moz-inline-box; /* FF2 & under */
display: inline-block;
vertical-align: top;
background-color:#F3C;
}
[B]* html .inline-blockElement{display:inline}
*+html .inline-blockElement{display:inline}[/B]
Any inline element (or a block element with a display of inline) that is in haslayout mode behaves as inline-block in IE7 and under. (I don’t usually have any problems with inline-block in ie8+ apart from the usual whitespace issues but I don’t doubt there are some odd bugs about.)
I’d also be questioning the use of inline-block on them altogether as why aren’t you just floating the parent containers?
I think you missed the part where the OP said they might be different height containers and didn’t want then to snag.
. I have used inline-block as each group of divs will have varying heights, so wanted to have them wrapping nicely.
I tend to use inline-block a lot these days especially for rows of images or blocks of content that may vary in height.
Thanks Paul - your solution has done the trick. (I had already sorted out the IE 6 & 7 fixes, but thnx for covering this anyway - and also thanks for pointing out that I was using inline-block to wrap uneven heights nicely - that was exactly my aim.)
The working page is: http://www.ekidnakinda.com.au/news/ekidna_news1.php
To satisy my curisosity, by adding an extra nested div to the code - is this best practice? Or could there have been a different way I could have achieved this?
Adding an extra div is always less than ideal but if you want to support older browsers like ff2 then it does seem to work well. It does depend on the situation and for simpler structures you wouldn’t need the extra div but when you have floats and other elements inside the inline-block parent it seems the extra div is needed. Others have had success using inline-stack instead of inline-box but I’ve found it just as buggy.