Make floating divs the same height

前端 未结 5 964
离开以前
离开以前 2020-12-01 16:24

I have 2 divs side by side. I don\'t know the height of them upfront, it changed according to the content. Is there a way to make sure they will always be the same height, e

5条回答
  •  暖寄归人
    2020-12-01 16:39

    You could try instead of using float, use display: table-cell. You might find some older browsers don't understand this rule however. See below:

    #wrapper {
        display: table; // See FelipeAls comment below
        width: 300px;
    }
    
    #left {
        display: table-cell;
        width: 50px;
        background: blue;
    }
    
    #right {
        display: table-cell;
        width: 250px;
        background: red;
    }
    

提交回复
热议问题