How do I keep two side-by-side divs the same height?

后端 未结 22 2765
自闭症患者
自闭症患者 2020-11-21 07:56

I have two divs side by side. I\'d like the height of them to be the same, and stay the same if one of them resizes. I can\'t figure this one out though. Ideas?

To c

22条回答
  •  孤独总比滥情好
    2020-11-21 08:21

    you can use jQuery to achieve this easily.

    CSS

    .left, .right {border:1px solid #cccccc;}
    

    jQuery

    $(document).ready(function() {
        var leftHeight = $('.left').height();
        $('.right').css({'height':leftHeight});
    });
    

    HTML

       

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi malesuada, lacus eu dapibus tempus, ante odio aliquet risus, ac ornare orci velit in sapien. Duis suscipit sapien vel nunc scelerisque in pretium velit mattis. Cras vitae odio sed eros mollis malesuada et eu nunc.

    Lorem ipsum dolor sit amet.

    You'll need to include jQuery

提交回复
热议问题