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

后端 未结 22 3151
自闭症患者
自闭症患者 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:15

    This question was asked 6 years ago, but it's still worthy to give a simple answer with flexbox layout nowadays.

    Just add the following CSS to the father

    , it will work.

    display: -webkit-flex;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    

    The first two lines declare it will be displayed as flexbox. And flex-direction: row tells browsers that its children will be display in columns. And align-items: stretch will meet the requirement that all the children elements will stretch to the same height it one of them become higher.

提交回复
热议问题