How to match height of floating sibling divs

后端 未结 5 511
醉酒成梦
醉酒成梦 2021-01-27 04:46

I have the following situation: http://jsfiddle.net/F3SqM/2/

I have two columns, I only know of the height of columnB. Both columns are floating, and I want columnA to m

相关标签:
5条回答
  • 2021-01-27 04:55

    You can use javascript to change the height of any other object, but you can't use CSS alone.

    You say the height of B is dynamic, but without your code it's a bit hard to see why it can be dynamic and how I could write the js code for you.

    0 讨论(0)
  • 2021-01-27 04:57

    Personally I like the equal height columns from www.ejeliot.com

    http://jsfiddle.net/spacebeers/s8uLG/3/

    You set your container up with overflow set to hidden, then on each div add negative margin-bottom and equal positive padding-bottom.

    #container { overflow: hidden; }
    #container div { float: left; background: #ccc; width: 200px; margin-bottom: -2000px; padding-bottom: 2000px; }
    #container .col2 { background: #eee; }
    
    <div id="container">
       <div>
            <p>Content 1</p>
       </div>
       <div class="col2">
            <p>Content 2</p>
            <p>Content 2</p>
            <p>Content 2</p>
            <p>Content 2</p>
       </div>
    </div>
    

    Faux Columns is also good and probably easier to set up but if you're really dead against using an image this is a pretty good method.

    0 讨论(0)
  • 2021-01-27 04:57

    Quickest fix would be to use display:table-cell instead of floating:

    http://jsfiddle.net/F3SqM/1/

    However, this will only work in IE8+...

    0 讨论(0)
  • 2021-01-27 04:59

    You could put column B inside column A, this would make column A wrap B and thus take the same height.

    0 讨论(0)
  • 2021-01-27 05:07

    you can give the required height to the parent element as in this example

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