Setting a length (height or width) for one element minus the variable length of another, i.e. calc(x - y), where y is unknown

后端 未结 6 2304
忘了有多久
忘了有多久 2020-11-28 12:50

I know we can use calc when lengths are defined:

flex-basis: calc(33.33% - 60px);
left: calc(50% - 25px);
height: calc(100em/5);

But what i

6条回答
  •  日久生厌
    2020-11-28 13:20

    Flexbox can do that.

    Support is IE10 and up.

    JSfiddle Demo

    * {
      margin: 0;
      padding: 0;
    }
    html,
    body {
      height: 100%;
    }
    #container {
      height: 100%;
      display: flex;
      flex-direction: column;
    }
    #top {
      background-color: lightgreen;
    }
    #bottom {
      background-color: lightblue;
      flex: 1;
    }
    green box variable height
    blue box no longer overflows browser window

提交回复
热议问题