Vitalii Petrychuk
Vitalii Petrychuk

Reputation: 14225

CSS3 flexbox adjust height of vertically aligned elements

Is it possible to make .item-1 height flexible and adjust .item-2 height? For example:

So depending on the content of the .item-1 we should resize it.

HTML

<div class="container">
    <div class="item item-1">1</div>
    <div class="item item-2">2</div>
</div>

CSS

html,
body,
.container {
    height: 100%;
}
.container {
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;

    -webkit-flex-flow: column;
    -moz-flex-flow: column;
    -ms-flex-flow: column;
    flex-flow: column;
}
.item {
    background: #eee;
    margin: 1px;
}
.item-1 {
  -webkit-box-flex: 3 3 100%;
  -moz-box-flex: 3 3 100%;
  -webkit-flex: 3 3 100%;
  -ms-flex: 3 3 100%;
  flex: 3 3 100%;
}
.item-2 {
  -webkit-box-flex: 1 1 100%;
  -moz-box-flex: 1 1 100%;
  -webkit-flex: 1 1 100%;
  -ms-flex: 1 1 100%;
  flex: 1 1 100%;
}

JSFiddle: http://jsfiddle.net/vpetrychuk/SYZtg/2

Upvotes: 0

Views: 4071

Answers (1)

cimmanon
cimmanon

Reputation: 68319

You can't do this with the 2009 Flexbox properties because there is nothing comparable to the flex-basis property (the box-flex property from the 2009 draft is not the same thing as the flex property from the modern draft, as it can only accept a single floating point value rather than 0-2 integers and 0-1 lengths).

http://codepen.io/cimmanon/pen/AGLge

html,
body,
.container {
  height: 100%;
}

.container {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}

.item {
  background: #eee;
  margin: 1px;
}

.item-1 {
  -webkit-flex: 1 1 10%;
  -ms-flex: 1 1 10%;
  flex: 1 1 10%;
}

.item-2 {
  -webkit-flex: 1 1 90%;
  -ms-flex: 1 1 90%;
  flex: 1 1 90%;
}

Upvotes: 1

Related Questions