CSS Layout How to - Create CSS FLEX Stretch to Width








Question

We would like to know how to create CSS FLEX Stretch to Width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#wrapper {<!-- w  w  w  .  ja  va2s  . c o m-->
  margin: 0;
  padding: 0;
  width: 100%;
  position: absolute;
  height: 100%;
  bottom: 0;
  background-color: #66CC33;
  -webkit-flex-direction: stretch;
  -moz-flex-direction: stretch;
  flex-direction: stretch;
  display: -webkit-flex;
  display: -moz-flex;
  display: flex;
}

.center {
  -webkit-flex-direction: column;
  -moz-flex-direction: column;
  flex-direction: column;
  display: -webkit-flex;
  display: -moz-flex;
  display: flex;
  width: 100%;
  height: 390px;
  margin: 5px;
  border-radius: 5px;
  background-color: #CC3399;
}
</style>
</head>
<body>
<body>
  <div id="wrapper">
    <div class="center"></div>
  </div>
</body>
</body>
</html>

The code above is rendered as follows: