CSS making two divs equal height with display table

前端 未结 2 874
自闭症患者
自闭症患者 2020-12-03 17:24

In the following HTML, the div .left and .right have different heights. Is it possible to make both divs same height without defining the height. I have tried using display:

相关标签:
2条回答
  • 2020-12-03 17:52

    Remove the float, which takes the elements out of the document's normal flow, and also add in another wrapper element, to act as the table-row:

    table-cell, behaves like the <td> HTML element

    Which implies that this requires (though I've not verified my inference) a display: table-row parent, as a td requires a tr parent-element.

    .wrap{
        overflow:hidden;
        width:250px;
        display: table;
        border-collapse: collapse;
    }
    
    .row {
        display: table-row;
    }
    .left{
        width: 50%;
        display: table-cell; 
        background-color: #0f0;
    }
    
    
    .right{
        width: 50%;
        background-color: #f00;
        display: table-cell;     
    }​
    

    JS Fiddle demo.

    References:

    • CSS display.
    0 讨论(0)
  • 2020-12-03 18:10

    Something like this?

    http://jsfiddle.net/fJbTX/3/

    I took out the float property

    0 讨论(0)
提交回复
热议问题