Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <html>
<head>
  <title>Flexbox Playground</title>
  <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
</head>
<body>
  <header class="header">
    <h2>Flexbox Playground by Marco Heine</h2>
    <p>This small demo shows the different Flexbox properties.<br> Use the following Options to see them in action.</p>
  </header>
  <div class="menu">
  <h2>Flexbox Container</h2>
    <div class="flexbox-container__select">
      <div>
        <label for="Display">Display</label><br>
        <select name="Display">
          <option value="flex">flex</option>
          <option value="inline-flex">inline-flex</option>
        </select>
      </div>
      <div>
        <label for="Flex-Direction">Flex-Direction</label><br>
        <select name="Display">
          <option value="column">column</option>
          <option value="row">row</option>
        </select>
      </div>
      <div>
        <label for="justify-content">Justify-Content</label><br>
        <select name="Justify-Content">
          <option value="flext-start">flex-start</option>
          <option value="flex-end">flex-end</option>
          <option value="center">center</option>
          <option value="space-between">space-between</option>
          <option value="space-around">space-around</option>
        </select>
      </div>
    </div>
  </div>
  <div class="container container-flex">
    <div class="item-1 item">Item 1</div>
    <div class="item-2 item">Item 2</div>
    <div class="item-3 item">Item 3</div>
    <div class="item-4 item">Item 4</div>
    <div class="item-5 item">Item 5</div>
    <div class="item-6 item">Item 6</div>
  </div>
</body>
</html>
              
            
!

CSS

              
                /* ================================= 
  General Styles
==================================== */

* {
  box-sizing: border-box;
}

body {
  background: #e8e9e9;
  color: #fff;
  font-size: 1.35em;
  font-family: 'Varela', sans-serif;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 5%;
}

.header,
.menu {
  background: #fff;
  border-radius: 5px;
  color: #000;
  margin: 45px auto;
  padding: 5px 0 30px 0;
  text-align: center;
}

label {
  font-size: 18px;
}

.flexbox-container__select {
  display: flex;
  justify-content: space-around;
}

.container {
  background: #fff;
  border-radius: 5px;
  margin: 45px auto;
  padding: 10px;
}

.item {
  background: #3db5da;
  border-radius: 5px;
  color: #fff;
  margin: 5px;
  padding: 15px;
}

/* ================================= 
  Flexbox Styles
==================================== */

.container-flex {
  display: flex;
  flex-direction: column;
}


              
            
!

JS

              
                //Select the Flexbox Container
var container = document.getElementsByClassName('container')[0];
//Select the select menu for the Display Property
var selectDisplay = document.getElementsByTagName('select')[0];
//Select the select menu for the Flex-Direction Property
var selectFlexDirection = document.getElementsByTagName('select')[1];
//Select the select menu for the justify-content Property
var selectJustifyContent = document.getElementsByTagName('select')[2];
//When another option from the select menu is chosen, call the function to change it's CSS property
selectDisplay.addEventListener('change', displayChanger, false);
selectFlexDirection.addEventListener('change', directionChanger, false);
selectJustifyContent.addEventListener('change', justifyContentChanger, false);



function displayChanger() {
  //Select the option's text from the select menu
  var selectedOptionText = selectDisplay.options[selectDisplay.selectedIndex].text;
  //Check the chosen select option
  if (selectedOptionText === 'inline-flex') {
    console.log(selectedOptionText);
    //Change the CSS property according to the chosen select option
    container.style.display = 'inline-flex';
  }
  else {
    console.log(selectedOptionText);
    container.style.display = 'flex';
  } 
}

function directionChanger() {
  var selectedOptionText = selectFlexDirection.options[selectFlexDirection.selectedIndex].text;
  if (selectedOptionText === 'row') {
    console.log(selectedOptionText);
    container.style.flexDirection = 'row';
  }
  else {
    console.log(selectedOptionText);
    container.style.flexDirection = 'column';
  } 
}

function justifyContentChanger() {
  var selectedOptionText = selectJustifyContent.options[selectJustifyContent.selectedIndex].text;
  if (selectedOptionText === 'flex-end') {
    console.log(selectedOptionText);
    container.style.justifyContent = 'flex-end';
  }
  else if (selectedOptionText === 'flex-start') {
    console.log(selectedOptionText);
    container.style.justifyContent = 'flex-start';
  } 
  else if (selectedOptionText === 'center') {
    console.log(selectedOptionText);
    container.style.justifyContent = 'center';
  }
  else if (selectedOptionText === 'space-between') {
    console.log(selectedOptionText);
    container.style.justifyContent = 'space-between';
  }
  else {
    console.log(selectedOptionText);
    container.style.justifyContent = 'space-around';
  }
}
              
            
!
999px

Console