Equally distributing height with CSS

后端 未结 3 1700
攒了一身酷
攒了一身酷 2021-01-21 15:46

I have an HTML problem that is pretty tricky and I\'m not sure there is a CSS-based solution for it. Basically I have a three column grid. The first and third columns can contai

3条回答
  •  花落未央
    2021-01-21 16:11

    Per recommendations by a few folks, I ended up using some simple javascript to get this done:

    $(document).ready(function() {
       var c1Rows = $(".col1 .row").length;
       var c3Rows = $(".col3 .row").length;
    
       var minHeight = 50;
       var max = Math.max(c1Rows, c3Rows);
       var totalHeight = max * minHeight;
    
       $(".col1 .row").css("height", totalHeight / c1Rows);
       $(".col2 .row").css("height", totalHeight);
       $(".col3 .row").css("height", totalHeight / c3Rows);
    });
    

提交回复
热议问题