CSS Layout How to - Create flex boxes with flex-grow and flex-shrink with fixed flex-basis








Question

We would like to know how to create flex boxes with flex-grow and flex-shrink with fixed flex-basis.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.child {<!--from   www. j a v  a 2 s  . co m-->
  padding: 10px;
  margin: 10px;
  background-color: #eee;
}

.container {
  padding: 10px;
  background-color: yellow;
  display: -webkit-flex;
  display: flex;
}

.child.one {
  -webkit-flex: 5 1 200px;
  flex: 5 1 200px;
  color: green;
}

.child.two {
  -webkit-flex: 1 3 200px;
  flex: 1 3 200px;
  color: purple;
}
</style>

</head>
<body>
  <div class="container">
    <div class="child one">
      Child One<br>Lorem ipsum<br>dolor sit amet<br>This is
      a bit longer line
    </div>
    <div class="child two">Two</div>
  </div>
</body>
</html>

The code above is rendered as follows: