Make div expand to occupy available height of parent container

前端 未结 9 456
别那么骄傲
别那么骄傲 2021-01-11 10:28

I have this code:

html:

short

Lorem ipsum dolor sit amet, consec
9条回答
  •  情歌与酒
    2021-01-11 10:55

    I would try another aproach. Using jquery you can calculate on window load the height of the highest h3 and then, apply that height to all your h3 inside your tiles.

    I know you asked for a pure css solution, so it's ok if I don't get any credit, but I think this answer may be usefull for other users with the same problem so that's why I wrote it.

    Something like this:

    var maxHeight = -1;
    $('.tile h3').each(function() {
        if ($(this).height() > maxHeight)
            maxHeight = $(this).height();
    });
    $('.tile h3').each(function() {
        $(this).height(maxHeight);
    });
    

    As you can see in this JSFIDDLE (notice I removed the fixed max-heightyou added to the header and add a third tilewith a "very long text" so you can check the exmaple better.

提交回复
热议问题