How might I force a floating DIV to match the height of another floating DIV?

前端 未结 11 674
悲&欢浪女
悲&欢浪女 2020-12-02 04:59

My HTML code is just dividing the pages into two columns, 65%,35% respectively.

11条回答
  •  天涯浪人
    2020-12-02 05:40

    The correct solution for this problem is to use display: table-cell

    Important: This solution doesn't need float since table-cell already turns the div into an element that lines up with the others in the same container. That also means you don't have to worry about clearing floats, overflow, background shining through and all the other nasty surprises that the float hack brings along to the party.

    CSS:

    .container {
      display: table;
    }
    .column {
      display: table-cell;
      width: 100px;
    }
    

    HTML:

    Column 1.
    Column 2 is a bit longer.
    Column 3 is longer with lots of text in it.

    Related:

    • jsfiddle
    • Using CSS “display: table-cell” for columns

提交回复
热议问题