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

后端 未结 22 3155
自闭症患者
自闭症患者 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条回答
  •  萌比男神i
    2020-11-21 08:12

    This is a common problem which many have encountered, but luckily some smart minds like Ed Eliot's on his blog have posted their solutions online.

    Basically what you do is make both divs/columns very tall by adding a padding-bottom: 100% and then "trick the browser" into thinking they aren't that tall using margin-bottom: -100%. It is better explained by Ed Eliot on his blog, which also includes many examples.

    .container {
        overflow: hidden;
    }
    .column {
        float: left;
        margin: 20px;
        background-color: grey;
        padding-bottom: 100%;
        margin-bottom: -100%;
    }
    Some content!
    Some content!
    Some content!
    Some content!
    Some content!
    Something

提交回复
热议问题