I’m having an issue with DIV height in which when I float several DIVs left, if any of them is too large, the alignment gets messed up. Please see here. One solution could be to set a fixed height that is larger. Is this the best solution? Is there a better way to handle this problem?
Yes - a common problem with floats. I think that inline-block will do what you want. Check out the part of Give Floats the Flick in CSS Layouts titled Display: inline-block; for explanation and code.
Yes, inline-block works much better in this case … although display: flex is even better these days.
In terms of inline-block, there are some gotchas, so something like this is worth considering:
.sectionMain {
word-spacing:-.25em; /* hide whitespace nodes in all modern browsers (not for webkit)*/
display:table;/* Webkit Fix */
}
.specs-box {
float: none;
display: inline-block;
vertical-align: top;
word-spacing:0; /* reset from parent*/
}
Flexbox is pretty well supported these days, though, so if you want to be brave, get rid of the float and try something like this instead of the code above:
Yes as mentioned above its a common problem with floats and when they wrap they will snag on anything in the way. You either have to have a fixed height for the floats or clear each row before you start again (not possible in a fluid layout of course).
Inline-block will do what you want without snagging. Here is an old codepen showing floats and then inline-blocks.
The only drawback with inline-block is that you get white space around the items (like the space between words) but usually this is not a problem. (There are fixes for the whitespace problem if needed.)
Thanks all. This is helpful, if not a bit over my head. My understanding of CSS layouts is pretty basic at the moment. I’ll get to work and maybe check back.
We’re happy to help you get it working if you need help. Actually, whichever method you choose, it’s a very simple tweak of your CSS to get things working nicely.
Question: I used box-sizing: border-box, made each item’s width 20%, and also encapsulated all item within a DIV that has no padding. Why isn’t there room for 5 across?
What you’ve done now works pretty well. calc has slightly better support than display: flex, but I’m at the point where I’m using flexbox now and to hell with older browsers, as it’s the way of the future. Of course, not everyone can afford to blow off older browsers.
I actually don’t mean a link. I’d like the user to be able to select multiple wearables and then click a “compare” button. The wearables would append a string to the subsequent URL in order to generate a table.
I can create another thread for this if necessary.