influxweb
3/7/2015 - 8:53 PM

CSS | Flexbox | Positioning HTML elements with CSS flexbox

CSS | Flexbox | Positioning HTML elements with CSS flexbox

/*--- Temp styling ---*/
.wrapper{
  display: flex; 
  flex-wrap: wrap; 
  width: 570px;
}
.container{
  background: #999;
  width: 180px;
  height: 180px;
  margin: 5px;
}
.box{
  width: 60px;
  height: 60px;
  background: orange;
}

/*--- Positioning with flexbox---*/
.container{display: flex;}

.top-left      {align-items: flex-start; justify-content: flex-start;}
.top-center    {align-items: flex-start; justify-content: center;}
.top-right     {align-items: flex-start; justify-content: flex-end;}

.center-left   {align-items: center; justify-content: flex-start;}
.center-center {align-items: center; justify-content: center;}
.center-right  {align-items: center; justify-content: flex-end;}

.bottom-left   {align-items: flex-end; justify-content: flex-start;}
.bottom-center {align-items: flex-end; justify-content: center;}
.bottom-right  {align-items: flex-end; justify-content: flex-end;}
<h1>Positioning HTML elements with CSS Flexbox</h1>
<div class="wrapper">
    <div class="container top-left">
        <div class="box"></div>
    </div>
    <div class="container top-center">
        <div class="box"></div>
    </div>
    <div class="container top-right">
        <div class="box"></div>
    </div>

    <div class="container center-left">
        <div class="box"></div>
    </div>
    <div class="container center-center">
        <div class="box"></div>
    </div>
    <div class="container center-right">
        <div class="box"></div>
    </div>

    <div class="container bottom-left">
        <div class="box"></div>
    </div>
    <div class="container bottom-center">
        <div class="box"></div>
    </div>
    <div class="container  bottom-right">
        <div class="box"></div>
    </div>
</div>

CSS | Flexbox | Positioning HTML elements with CSS flexbox

A Pen by Torben Colding on CodePen.

License.