cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="cont">
  <h1>Flexbox Align & Justify Examples
  <br>flex-direction: column</h1>

  <h2>Initial values:</h2>
  <ul>
    <li>align-items: stretch</li>
    <li>justify-content: flex-start</li>
  </ul>

  <p>The width of the flex items defaults to auto, as these are block level elements they stretch to the full width of their parent. So the flex-container is full width and align-items stretch means the items stretch to meet it.</p>
</div>
<div class="code">
  <div class="wrapper example1">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>

<div class="cont">
  <h2>Changing the height of the container</h2>

  <p>I have given the flex container a height of 25em. As justify-content is flex-start the items display at the start of the flex container.</p>
</div>
<div class="code">
  <div class="wrapper example2">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>
<div class="cont">
  <h2>align-items: flex-start</h2>
  <p>The items align to the start of the flex container.</p>
</div>
<div class="code">
  <div class="wrapper example3">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>

<div class="cont">
  <h2>align-items: flex-end</h2>
  <p>The items align to the end of the flex container.</p>
</div>
<div class="code">
  <div class="wrapper example4">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>

<div class="cont">
  <h2>justify-content: space-between</h2>
  <p>Spacing items out evenly and flush with top and bottom of the container. Youwill only get space between elements if the container is taller than the sum of the items (if you have added a height).</p>
</div>
<div class="code">
  <div class="wrapper example7">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>

<div class="cont">
  <h2>justify-content: space-around</h2>
  <p>Spacing items out evenly with space all around.</p>
</div>
<div class="code">
  <div class="wrapper example8">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>

<div class="cont">
  <h2>justify-content: flex-end</h2>
  <p>Justifying to the end of the flex container.</p>
</div>
<div class="code">
  <div class="wrapper example9">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>

<div class="cont">
  <h2>justify-content: center</h2>
  <p>Justifying to the center of the flex container.</p>
</div>
<div class="code">
  <div class="wrapper example10">
    <div>One
      <br>... is taller
      <br>than the rest.</div>
    <div>Two</div>
    <div>Three</div>
    <div>Four</div>
    <div>Five</div>
    <div>Six</div>
  </div>
</div>


</div>
            
          
!
            
              .example2 {
  height: 25em;
}

.example3 {
  height: 25em;
  align-items: flex-start;
}

.example4 {
  height: 25em;
  align-items: flex-end;
}

.example5 {
  height: 25em;
  align-items: center;
}

.example6 {
  height: 25em;
  align-items: baseline;
}

.example6 div:first-child {
  font-size: 150%;
}

.example7 {
  height: 30em;
  justify-content: space-between;
}

.example8 {
  height: 30em;
  justify-content: space-around;
}

.example9 {
  height: 30em;
  justify-content: flex-end;
}

.example10 {
  height: 30em;
  justify-content: center;
}


.wrapper {
  width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background-color: #fafafa;
}

.wrapper div {
  padding: 10px;
  background-color: rgb(41,73,130);
  color: #fff;
  border-radius: 5px;
}

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

body {
  font: 1em/1.4 Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
  background-color: #fafafa;
  color: #000;
  margin:0;
}

.cont {
  width: 800px;
  margin: 0 auto;
}

.code {
  background-color: #333;
  padding: 20px;
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console