Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1><code>display: flex</code> vs <code>display: inline-flex</code></h1>
<subtitle>What's the difference?</subtitle>

<h2>Example 1: <code>display: flex</code></h2>
<p>Three containers <span class="flex-color">in this color</span> with <code>display: flex</code>, containing three child divs <span class="inline-color">in this color</span> with <code>flex: 1</code>.</p>
<p>Each <span class="flex-color">parent container</span> sits on its own line. The <span class="inline-color">three children</span> occupy an equal width.</p>
<div class="container--flex">
  <div class="flex-child"></div>
  <div class="flex-child"></div>
  <div class="flex-child"></div>
</div>
<div class="container--flex">
  <div class="flex-child"></div>
  <div class="flex-child"></div>
  <div class="flex-child"></div>
</div>
<div class="container--flex">
  <div class="flex-child"></div>
  <div class="flex-child"></div>
  <div class="flex-child"></div>
</div>

<h2>Example 2: <code>display: inline-flex</code></h2>
<p>Three containers <span class="flex-color">in this color</span> with <code>display: inline-flex</code>, containing three child divs <span class="inline-color">in this color</span> with <code>flex: 1</code> and <code>min-width: 50px</code>.</p>
<p>Each <span class="flex-color">parent container</span> sits next to the other one, since they can all fit on the same row. The width of the <span class="flex-color">parent container</span> is dependent on the size of <span class="inline-color">the children</span>, which here have been given a min-width of 50px.</p>
<div class="container--inline-flex">
  <div class="flex-child"></div>
  <div class="flex-child"></div>
  <div class="flex-child"></div>
</div>
<div class="container--inline-flex">
  <div class="flex-child"></div>
  <div class="flex-child"></div>
  <div class="flex-child"></div>
</div>
<div class="container--inline-flex">
  <div class="flex-child"></div>
  <div class="flex-child"></div>
  <div class="flex-child"></div>
</div>

<h2>Explanation</h2>
<p>An element with <code>display: flex</code> is similar to an element with <code>display: block</code>, whereby it occupies the whole row. However, its child elements can be positioned flexibly and dynamically, compared to previously-available layout properties.</p>
<p>If we change this to <code>display: inline-flex</code>, it:
  <ul>
    <li>makes the parent container display inline</li>
    <li>still applies all flex properties to the children, no differently form <code>display: flex</code></li>
  </ul>
  This means that if the child elements aren't too big, two containers with <code>display: inline-flex</code> can sit side-by-side.
</p>
<p>Other display properties also have an inline counterpart:</p> 
<ul><li><code>block</code> has <code>inline-block</code></li>
  <li><code>table</code> has <code>inline-table</code></li>
  <li>and even <code>grid</code> has <code>inline-grid</code></li>
  <p><a href="https://www.w3.org/TR/css-flexbox-1/#flex-containers">Read more about the flex display property in the W3 spec.</a></p>
              
            
!

CSS

              
                $flexColor: #64B5F6;
$inlineColor: #F06292;

.container--inline-flex,
.container--flex {
  background-color: $flexColor;
  margin-bottom: 10px; /* just for aesthetics */
}
.container--flex {
  display: flex;
}
.container--inline-flex {
  display: inline-flex;
}
.flex-child {
  flex: 1;
  min-width: 50px;
  min-height: 50px;
  margin: 10px;
  background-color: $inlineColor;
}

.flex-color {
  color: $flexColor;
}
.inline-color {
  color: $inlineColor;
}

/* Remaining styles are just to make the demo look nice */
body {
  font-family: 'Open Sans', sans-serif;
}
code {
  background-color: #EEEEEE;
  padding: 1px 5px;
}
              
            
!

JS

              
                
              
            
!
999px

Console