css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="copy">
  <p>Specification texts are taken from the W3C specification 
    <a href="http://www.w3.org/TR/css3-flexbox/#align-content">W3C CSS Flexible Box Layout Module</a><br><span class="self">Own comments and notes in blue color.</span></p>
</div>

<div class="explain">
  <h1>Flexbox: margin</h1>
    
  Auto margins on flex items have an effect very similar to auto margins in block flow:
<ul>
  <li>During calculations of flex bases and flexible lengths, auto margins are treated as ‘0’.</li>
  <li>Prior to alignment via ‘justify-content’ and ‘align-self’, any positive free space is distributed to auto margins in that dimension.</li>
  <li>Overflowing elements ignore their auto margins and overflow in the end/foot direction.</li>
  </ul>
  <p>
    Note that, if free space is distributed to auto margins, the alignment properties will have no effect in that dimension because the margins will have stolen all the free space left over after flexing.
  </p>
  
</div>

<h2>Demos</h2>
<h3 class="separator">
  margin: auto;
</h3>
<p class="self">
  // horizontal and vertical centering
</p>
<div class="flexboxContainer ">
  <div class="flexboxItem m-auto">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus temporibus?</div>
</div>
  
<h3 class="separator">
  margin-left: auto at second item
</h3>
<p class="self">
  // a possibility to group the flex-items
</p>
<div class="flexboxContainer ">
  <div class="flexboxItem">Lorem ipsum dolor sit amet,</div>
  <div class="flexboxItem ml-auto">Lorem ipsum dolor sit amet, </div>
  <div class="flexboxItem">Lorem ipsum dolor sit amet, </div>
</div>
  
<h3 class="separator">
  margin-left: auto at second and fourth item
</h3>
<p class="self">
  // here: create three groups
</p>
<div class="flexboxContainer ">
  <div class="flexboxItem">Lorem ipsum dolor sit amet,</div>
  <div class="flexboxItem ml-auto">Lorem ipsum dolor sit amet, </div>
  <div class="flexboxItem">Lorem ipsum dolor sit amet,</div>
  <div class="flexboxItem ml-auto">Lorem ipsum dolor sit amet, </div>
  <div class="flexboxItem">Lorem ipsum dolor sit amet, </div>
</div>
  
<h3 class="separator">
  margin-top: auto at last item
</h3>
<p class="self">
  // here: create two groups | flex-direction is column
</p>
<div class="flexboxContainer flex-direction-column">
  <div class="flexboxItem">Lorem ipsum dolor</div>
  <div class="flexboxItem">Lorem ipsum dolor</div>
  <div class="flexboxItem mt-auto">Lorem ipsum dolor</div>
</div>
  
<h3 class="separator">
  margin-top: auto at last item with align-items:flex-start
</h3>
<p class="self">
  // here: create two groups | flex-direction is column<br>
  // same result as above - the align-items property has no effect because margin-top: auto has stolen the free space
</p>
<div class="flexboxContainer flex-direction-column flex-align-items-flex-start">
  <div class="flexboxItem">Lorem ipsum dolor</div>
  <div class="flexboxItem">Lorem ipsum dolor</div>
  <div class="flexboxItem mt-auto">Lorem ipsum dolor</div>
</div>
  
<h3 class="separator">
  No margin-top: auto at last item with align-items:flex-start
</h3>
<p class="self">
  // align-items property works
</p>
<div class="flexboxContainer flex-direction-column flex-align-items-flex-start">
  <div class="flexboxItem">Lorem ipsum dolor</div>
  <div class="flexboxItem">Lorem ipsum dolor</div>
  <div class="flexboxItem">Lorem ipsum dolor</div>
</div>
            
          
!
            
              .flexboxContainer {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row wrap;
  flex-flow: row wrap;
  min-height: 30rem;
  min-width: 80rem;
  background: #a7a9aa;
}

.flexboxContainer.flex-direction-column {
  -webkit-flex-flow: column wrap;
  flex-flow: column wrap;
}

.flex-align-items-flex-start {
  -webkit-align-items: flex-start;
  align-items: flex-start;
}

.flexboxItem {
  width: 10rem;
  background-color: #b94a48;
  color: #fff;
  border: 1px dashed #333;
  padding: 1rem;
}

.m-auto {
  margin: auto;
}

.ml-auto {
  margin-left: auto;
}

.mt-auto {
  margin-top: auto;
}

html {
  font-size: 62.5%;
}
body {
  font-size: 1.6rem;
  padding: 2rem;
  max-width: 130rem;
}

.explain {
	background: #efefef;
	padding: 2rem;
}

.copy {
  color: #b94a48;
  font-weight: bold;
  font-size: 1.8rem;
}

.self {
  color: #428bca;
}

.separator {
  background-color: #f0ad4e;
  padding: 1.5rem 1rem;
  margin: 2rem 0;
}

.smallSeparator {
  background-color: #2980b9;
  padding: 0.5rem 1rem;
  margin: 2rem 0;
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console