html css 2 column layout, both columns same height automatically?

前端 未结 2 579
感情败类
感情败类 2020-12-10 23:19

I have a two column layout set up, and I want to have both columns automatically stretch to fill parent div of the two columns, The reason being that the left column has a b

相关标签:
2条回答
  • 2020-12-11 00:06

    You can use CSS table layout (not HTML table layout, that would be poor semantics):

    .container {
        display: table;
        table-layout: fixed;
        width: 944px;
        font-size: 0.75em;
    
    }
    .col {
        display: table-cell;
        vertical-align: top;
    }
    
    .container .left
    {
        width: 236px;
        background-color:grey;
    }
    .container .right
    {
        width: 708px;
        background-color:yellow;
    }
    <div class="container">
        <div class="col left">Left</div>
        <div class="col right">Right
        </br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>Hey
          
        </div>
    </div>

    Compatibility is IE8+ and fallback for IE6/7 if needed is exactly the same as for inline-block

    Longer explanations in previous answers: here and there with also the good old method of faux-columns (your design must be thought with this technique in mind)

    0 讨论(0)
  • 2020-12-11 00:14

    Try this: http://jsfiddle.net/scrimothy/Y2ZsJ/

    Just add this to your css:

    .container { overflow: hidden; }
    .container div { 
      padding-bottom: 9999px;
      margin-bottom: -9999px;
    }
    

    (from: http://css-tricks.com/fluid-width-equal-height-columns/ under the heading: One True Layout Method)

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