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

后端 未结 22 2803
自闭症患者
自闭症患者 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条回答
  •  灰色年华
    2020-11-21 08:04

    I'm surprised that nobody has mentioned the (very old but reliable) Absolute Columns technique: http://24ways.org/2008/absolute-columns/

    In my opinion, it is far superior to both Faux Columns and One True Layout's technique.

    The general idea is that an element with position: absolute; will position against the nearest parent element that has position: relative;. You then stretch a column to fill 100% height by assigning both a top: 0px; and bottom: 0px; (or whatever pixels/percentages you actually need.) Here's an example:

    
    
      
        
      
      
        
    • Foo
    • Bar
    • Baz
    Lorem ipsum

提交回复
热议问题