css flexbox: same height for all elements?

前端 未结 4 833
慢半拍i
慢半拍i 2021-01-12 09:59

Using CSS and flexbox, I don\'t understand how to give the same height to divs \"a\" and \"b\". I need b to become taller so as to match a\'s height. In other words, the gre

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 10:34

    I solved the problem in javascript as follows, but I am still interested in a css solution:

    function computeMaxHeight(els) {
        var ht = 0;
        els.forEach(function (el) {
            var elht = el.height();
            if (elht > ht) {
                ht = elht;
            }
        });
        return ht;
    }
    
    function setMinMeight(els) {
        var maxht = computeMaxHeight(els);
        //console.log("here resize. maxht = " + maxht);
    
        els.forEach(function (el) {
            el.css('min-height', maxht);
        });
    
    }
    
    $(document).ready(function () {
    
        var els = [$("#non-porre-limiti"), $("#we-love-pagi"), $("#vuoto"), $("#pagiletter"), $("#pagi-focus")];
    
        $(window).on('resize', function () {
            setMinMeight(els);
    
        });
    
        setMinMeight(els);
    
    });
    

    fiddle: http://jsfiddle.net/s2b0v4ph/3/

提交回复
热议问题