I have a horizontal div and I want the height of the elements in it to all be the same. The thing is, one of them is in two rows. I was thinking of setting the height of the div by setting the line-heights of the elements contained in it, but on one of the inside elements (it’s split into two rows), I can’t figure out how to do it. The line height should be in this example 2.6 (x100% which is default in pure.css), but if I set the table-row spans to add up to 2.6, they push the height of the div further than the elements that are specified to line-height 2.6. For some reason, it seems to work when I add them up to 2.5 (1 + 0.5) like in the code below. I can’t figure out why.
A somewhat working example of what I want is available at http://tinyurl.com/oy4r756, however it doesn’t work in all situations and I wanted to start afresh with some more understanding of what’s going on.
You seem to be making this a lot harder than it should be.
I would simply put all those links in the same structure and use display:table-cell to keep them all the same height automatically. No need for weird calculations (as a general rule you would never set line-height to less than .9 or you may end up hiding the glyphs).
Yes, I’ve noticed myself doing that. The live example I linked was basically hacked together in a way that worked most of the time but not in a way I understood (especially coming back to it a while after I first coded it) so I wanted to start fresh with methods I understood, but ended up doing the same thing. This makes sense because the tallest cell will force the other ones to expand vertically automatically. Thanks for the help
I think I may have done it again. Let’s say that I want to mark up the links as an unordered list (either because I think it makes more sense for a list of links, or I might want to add dropdown links in the future). I also think I can remove the container div, giving me this markup:
But now I’ve set myself up into using the line-height method again, haven’t I? The point is that I need the anchor to take up the height of its parent, the li (table-cell), while having the text of the anchor vertically centered within itself. Is the line-height method the only way of achieving this?
That’s why I used the html5 nav element because it is meant for a list of nav links but without implicitly using a list structure. There’s no need to put a list inside a nav element as the semantics of the nav element define its use perfectly without further mark up.
The problem with your method that is is now the list element that has full height and not the anchors (even though you give them 100% height that will only refer to the current cell and not adjacent cells (assuming that browsers let you use height:100% on cell content which is not always the case)). It also means you lose the vertical alignment because your anchor is now `100% tall so there is nothing to center; you would then need another cell inside the anchor to mimic yet another table.