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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

<body>

    <nav id="navbar">
      <header>
        <h1  id="header"><span id="title"><strong> Basic concepts of flexbox</strong></span> </h1>
      </header>

      <ul class="sidebar">
        <li><a class="nav-link" href="#introduction">Introduction</a></li>
        <li><a class="nav-link" href="#two_axes_of_flexbox">Two axes of flexbox</a></li>

        <li><a class="nav-link" href="#start_and_end_lines">Start and end lines</a></li>

        <li><a class="nav-link" href="#the_flex_container">The flex container</a></li>

        <li><a class="nav-link" href="#multi-line_flex_containers_with_flex-wrap">Multi-line flex containers with flex-wrap</a></li>

        <li><a class="nav-link" href="#the_flex-flow_shorthand">The flex-flow shorthand</a></li>

        <li><a class="nav-link" href="#properties_applied_to_flex_items">Properties applied to flex items</a></li>
        <li><a class="nav-link" href="#alignment,_justification_and_distribution_of_free_space_between_items">Alignment, justification and distribution of free space between items</a></li>

        <li><a class="nav-link" href="#reference">Reference</a></li>
      </ul>

    </nav>
  </header>

  <!--Main content(technical documentation)-->
  <main id="main-doc">

    <section class="main-section" id="introduction">
      <header>
        <h2 id="introduction"><strong>Introduction</strong></h2>
      </header>
      <article>
        <!--text that describes the topic of this section-->

        <p>The Flexible Box Module, usually referred to as flexbox, was designed as a one-dimensional layout model, and as a method that could offer space distribution between items in an interface and powerful alignment capabilities. This article gives
          an outline of the main features of flexbox, which we will be exploring in more detail in the rest of these guides.
        </p>
        <p>When we describe flexbox as being one dimensional we are describing the fact that flexbox deals with layout in one dimension at a time — either as a row or as a column. This can be contrasted with the two-dimensional model of CSS Grid Layout,
          which controls columns and rows together.</p>
      </article>
    </section>
    <!-- Topic 2 Two Axes-->
    <section class="main-section" id="two_axes_of_flexbox">

      <header>
        <article>
          <h2>Two axes of flexbox</h2>
      </header>
      <p>When working with flexbox you need to think in terms of two axes — the main axis and the cross axis. The main axis is defined by the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction" target="_blank">flex-direction</a> property,
        and the cross axis runs perpendicular to it. Everything we do with flexbox refers back to these axes, so it is worth understanding how they work from the outset</p>

      <!--main axis-->
      <h3><span id="main_axis">The main axis</span></h3>
    
    <p>The main axis is defined by flex-direction, which has four possible values:</p>
  
     <ul>
    <li>row</li>
    <li>row-reverse</li>
    <li>column</li>
    <li>column-reverse</li>
       </ul>
   <p>Should you choose row or row-reverse, your main axis will run along the row in the <strong>inline direction</strong>.</p>
<h3><span id="cross_axis">The cross axis</span></h3>

      <p> The main axis is defined by flex-direction, which has four possible values:</p>

      <ul>
        <li>row</li>
        <li>row-reverse</li>
        <li>column</li>
        <li>column-reverse</li>
      </ul>
      <p>Should you choose row or row-reverse, your main axis will run along the row in the <strong>inline direction</strong>.</p>

      <p>Choose column or column-reverse and your main axis will run from the top of the page to the bottom — in the <strong>block direction</strong>.</p>

      </article>
    </section>

    <section class="main-section" id="start_and_end_lines">

      <header>
        <h2>Start and end lines
          </h2>
      </header>
      <article>
        <p>Another vital area of understanding is how flexbox makes no assumption about the writing mode of the document. In the past, CSS was heavily weighted towards horizontal and left-to-right writing modes. Modern layout methods encompass the range
          of writing modes and so we no longer assume that a line of text will start at the top left of a document and run towards the right hand side, with new lines appearing one under the other.</p>
        <p>You can read more about the relationship between flexbox and the Writing Modes specification in a later article, however the following description should help explain why we do not talk about left and right and top and bottom when we describe
          the direction that our flex items flow in.</p>
        <p>If the flex-direction is row and I am working in English, then the start edge of the main axis will be on the left, the end edge on the right.</p>
        <p>If I were to work in Arabic, then the start edge of my main axis would be on the right and the end edge on the left.</p>
        <p>After a while, thinking about start and end rather than left and right becomes natural, and will be useful to you when dealing with other layout methods such as CSS Grid Layout which follow the same patterns.</p>
      </article>
    </section>

    <section class="main-section" id="the_flex_container">
      <header>
        <h2>The flex container
          </h2>
      </header>
      <article>
        <p>An area of a document laid out using flexbox is called a flex container. To create a flex container, we set the value of the area's container's display property to flex or inline-flex. As soon as we do this the direct children of that container
          become flex items. As with all properties in CSS, some initial values are defined, so when creating a flex container all of the contained flex items will behave in the following way.
        </p>

        <code> .box {
       display: flex;
       }
     </code>

        <pre> <code>
   &lt;div class="box"&gt;
          &lt;div&gt;One&lt;/div&gt;
           &lt;div&gt;Two&lt;/div&gt;
           &lt;div&gt;Three&lt;div&gt;
               &lt;br&gt;has
               &lt;br&gt;extra
               &lt;br&gt;text
           &lt;/div&gt;
         &lt;/div&gt;
         </code>
   </pre>

        <ul>
          <li>Items display in a row (the flex-direction property's default is row).</li>
          <li>The items start from the start edge of the main axis.</li>
          <li>The items do not stretch on the main dimension, but can shrink.</li>
          <li>The items will stretch to fill the size of the cross axis.</li>
          <li>The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis" target="_blank"> flex-basis</a> property is set to auto.</li>
          <li>The
            <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap" target="_blank"> flex-wrap</a> property is set to nowrap.</li>
        </ul>
        <p>The result of this is that your items will all line up in a row, using the size of the content as their size in the main axis. If there are more items than can fit in the container, they will not wrap but will instead overflow. If some items are
          taller than others, all items will stretch along the cross axis to fill its full size.</p>
        <h3><span id="changing_flex_direction">Changing flex direction</span></h3>
        <p>Adding the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-direction" target="_blank">flex-direction</a> property to the flex container allows us to change the direction in which our flex items display. Setting flex-direction: row-reverse
          will keep the items displaying along the row, however the start and end lines are switched.</p>

        <p>If we change flex-direction to column the main axis switches and our items now display in a column. Set column-reverse and the start and end lines are again switched. </p>

        <code>
        .box {
          display: flex;
          flex-direction: row-reverse;
        }
     </code>
        <pre><code>
   &lt;div class="box"&gt;
          &lt;div&gt;One&lt;/div&gt;
           &lt;div&gt;Two&lt;/div&gt;
           &lt;div&gt;Three&lt;div&gt;
           &lt;/div&gt;
         &lt;/div&gt;
         </code>
   </pre>

      </article>
    </section>

    <section class="main-section" id="multi-line_flex_containers_with_flex-wrap">

      <header>
        <h2>Multi-line flex containers with flex-wrap
          </h2>
      </header>
      <article>
        <p>While flexbox is a one dimensional model, it is possible to cause our flex items to wrap onto multiple lines. In doing so, you should consider each line as a new flex container. Any space distribution will happen across that line, without reference
          to the lines either side.</p>

        <p>To cause wrapping behaviour add the property <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap" target="_blank">flex-wrap</a> with a value of wrap. Now, should your items be too large to all display in one line, they will wrap
          onto another line. The live sample below contains items that have been given a width, the total width of the items being too wide for the flex container. As flex-wrap is set to wrap, the items wrap. Set it to nowrap, which is also the initial
          value, and they will instead shrink to fit the container because they are using initial flexbox values that allows items to shrink. Using nowrap would cause an overflow if the items were not able to shrink, or could not shrink small enough to
          fit.</p>

        <code>    .box {
        display: flex;
        flex-wrap: wrap;
     }</code>

        <pre><code>
   &lt;div class="box"&gt;
          &lt;div&gt;One&lt;/div&gt;
           &lt;div&gt;Two&lt;/div&gt;
           &lt;div&gt;Three&lt;div&gt;
           &lt;/div&gt;
         &lt;/div&gt;
         </code>
   </pre>

        <p>Find out more about wrapping flex items in the guide 
          <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Mastering_Wrapping_of_Flex_Items" target="_blank">Mastering Wrapping of Flex Items.</a></p>
      </article>
    </section>

    <section class="main-section" id="the_flex-flow_shorthand">

      <header>
        <h2>The flex-flow shorthand
          </h2>
      </header>
      <article>
        <p>You can combine the two properties flex-direction and flex-wrap into the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-flow" target="_blank">flex-flow</a> shorthand. The first value specified is flex-direction and the second value
          is flex-wrap.</p>

      </article>

    </section>

    <section class="main-section" id="properties_applied_to_flex_items">

      <header>
        <h2>Properties applied to flex items</h2>
      </header>
      <article>
        <p>To have more control over flex items we can target them directly. We do this by way of three properties:</p>

        <ul>
          <li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow" target="_blank"> flex-grow</a></li>
          <li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow" target="_blank">flex-shrink</li></a>
           <li> <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-grow">
              <li>flex-basis</li>
            </a>
        </ul>
        <p>We will take a brief look at these properties in this overview, and you can gain a fuller understanding in the guide <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Controlling_Ratios_of_Flex_Items_Along_the_Main_Ax"
            target="_blank">Controlling Ratios of Flex Items on the Main Axis</a>.</p>

        <p>Before we can make sense of these properties we need to consider the concept of available space. What we are doing when we change the value of these flex properties is to change the way that available space is distributed amongst our items. This
          concept of available space is also important when we come to look at aligning items.</p>

        <p>If we have three 100 pixel-wide items in a container which is 500 pixels wide, then the space we need to lay out our items is 300 pixels. This leaves 200 pixels of available space. If we don’t change the initial values then flexbox will put that
          space after the last item.</p>

        <p>This flex container has available space after laying out the items.</p>

        <p>If we instead would like the items to grow and fill the space, then we need to have a method of distributing the leftover space between the items. This is what the flex properties that we apply to the items themselves, will do.

        </p>
      </article>
    </section>

    <section class="main-section" id="alignment,_justification_and_distribution_of_free_space_between_items">

      <header>
        <h2>Alignment, justification and distribution of free space between items
          </h2>
      </header>
      <article>
        <h3><span class="subtitle">Align-items</span></h3>
        <p>The align-items property will align the items on the cross axis. The initial value for this property is stretch and this is why flex items stretch to the height of the tallest one by default. They are in fact stretching to fill the flex container
          — the tallest item is defining the height of that. You could instead set align-items to flex-start in order to make the items line up at the start of the flex container, flex-end to align them to the end, or center to align them in the centre.
          Try this in the live example — I have given the flex container a height in order that you can see how the items can be moved around inside the container. See what happens if you set the value of align-items to:</p>

        <ul>
          <li>stretch</li>
          <li>flex-start</li>
          <li>flex-end</li>
          <li>center</li>
        </ul>
   
      </article>
    </section>

    <section>
   
        <header>
          <h3><span class="subtitle">Justify-content</span></h3>
        </header>
      <article>
        <p> The justify-content property is used to align the items on the main axis, the direction in which flex-direction has set the flow. The initial value is flex-start which will line the items up at the start edge of the container, but you could also
          set the value to flex-end to line them up at the end, or center to line them up in the centre.</p>

        <p>You can also use the value space-between to take all the spare space after the items have been laid out, and share it out evenly between the items so there will be an equal amount of space between each item. To cause an equal amount of space on
          the right and left of each item use the value space-around. With space-around, items have a half-size space on either end. Or, to cause items to have equal space around them use the value space-evenly. With space-evenly, items have a full-size
          space on either end.</p>

        <p>Try the following values of justify-content in the live example:</p>
        <ul>
          <li>flex-start</li>
          <li>flex-end</li>
          <li>center</li>
          <li>space-around</li>
          <li>space-between</li>
          <li>space-evenly</li>
        </ul>
        <p>In the article <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container" target="_blank">Aligning Items in a Flex Container</a> we will explore these properties in more depth, in order
          to have a better understanding of how they work. These simple examples however will be useful in the majority of use cases.</p>
      </article>
        </section>

        <section class="main-section" id="reference">

          <header>
            <h2>Reference
              </h2>
          </header>
              <article>
          <p>All information in this paper was referenced from Mozilla.org's<a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox"> Basic concepts of flexbox</a>.
              </article>
              </section>
  </main>
           
        </body>
              
            
!

CSS

              
                @media all and (min-width: 769px) and (max-width: 4000px) {
  body {    
    font-family: 'Noto Sans JP', sans-serif;
  color: black;
  line-height: 1.5;
  background-color: #fff;
}
  

#header {
  display: inline;
}


pre code {
  
  display: block;
  margin: 0 auto;
  padding: 1em;
  width: 250px;
  height: auto;
white-space: normal;
  background-color: #f4f5f7; 


}
  
code {
  display: block;
   margin: 0 auto;
  width: 250px;
  height: auto;
  background-color: #f4f5f7;
  padding: 1em;
  white-space: normal;
}

p {
  margin: 0;
  padding: 1em;
 font-size: 1em;
  
}

  #introduction {
    margin-top: 26px;
  }
h1,h2,h3,h4,h5 {
  margin-bottom: 0;
}

/*nav {
  position: relative;
  top:0;
  left: -90px;
  
}*/
  

#navbar {
  float: left; 
  position:sticky;
  top: 0;
  left: 0;
  width: 256px;
  overflow-y: auto;
height: 100%;
}

 #main-doc {
    display: flex;
    flex-flow: column nowrap;

  }

.nav-link {
  display: flex;
  flex-direction: column;
 text-decoration: none;
 padding: .5em;
  color: #000;
     font-size: 1em;
  overflow-y: auto;
  

  
}
.nav-link a {
  display: block;
  color: red; 
}
 a:hover {
  color: #999;
}
a:visited {
  color: green;
}

nav ul {
  
  display: block;
 padding-left: 0;
  margin-left:0; 
    width: 248px;
  height: 100%;
  
}

nav li {
  width: 100%;
  background-color: #ffffff;
   list-style: none;
   border: 1px solid black;
  padding: .25em;
  margin: 0;

}

#title {
 display: inline-flex;
  flex-wrap: nowrap;
  flex: 0 0 initial;
  background-color: gray;
  width: 256px;
  height: 100px;
  padding-top:20px; 
  padding-bottom: 20px;
 text-align: center;

  
}
  
  h1 {
     flex: 0 0 initial;
    font-size:2em;
  }
  
  h2 {
    width: 100%;
    font-size: 1.5em;
  }

.main-section {
 display: flex;
  flex-flow: column wrap; 
  padding: 1em;
  font-size: 3.vw;
  max-width: 800px;
  margin-top: 75px;
}


li {
 margin-left: 2em; 
  font-size: 1em;
}

  h3 {
    font-size: 1.25em;
  }

#main_axis {
  display: inline-block;
  margin-top: .25em;
  margin-left: 1em;
 
}
#main_axis p {
  margin-left:3em;
  padding-left: 0;
 
}

#cross_axis {
   display: inline-block;
  margin-top: -2em;
  margin-left: 1em;
  overflow: hidden;
}

#changing_flex_direction {
   display: inline-block;
  margin-top: -2em;
  margin-left: 1em;
  overflow: hidden;
}

#align-items {
    display: inline-block;
  margin-top: -2em;
  margin-left: 1em;
  overflow: hidden;
}
.subtitle{
    display: inline-block;
  margin-top: -2em;
  margin-left: 1em;
  overflow: hidden;
  margin-bottom: 0;
} 
}


/*Mobile Version****************************/
@media (max-width : 768px) {

  
  body {
    margin: 0 auto;
    font-family: 'Noto Sans JP', sans-serif;
    
  color: black;
    line-height: 1.5em;
    
}
  
pre code {
  
  display: block;
  margin: 0 auto;
  padding: 1em;
  width: 250px;
  height: auto;
white-space: normal;
  background-color: #f4f5f7; 


}
  
code {
  display: block;
   margin: 0 auto;
  width: 250px;
  height: auto;
  background-color: #f4f5f7;
  padding: 1em;
  white-space: normal;
  
}
  #title {
    
  }
  


p {
  font-size: 1em;
  padding-left: 2.5em;
}

h1,h2,h3,h4,h5 {
  margin-bottom: 0;
  margin-left: .5em;
}
  h3 {
    padding-left: 1em;
  }

/*nav {
  position: relative;
  top:0;
  left: -90px;
  
}*/
#header {
width: 100%;
}


nav {
    width: 100%;
  z-index: 10;
}

#navbar {
 display: flex;
  flex-direction: column;
  flex-flow: flex-start;
flex: 1 0 auto;
  
 
}

.nav-link {
 text-decoration: none; 
 padding-left: 1em;
  color: #000;
  
}
.nav-link a {
  color: red; 
}
 a:hover {
  color: #999;
}
a:visited {
  color: green;
}

nav ul {
  float: left;
 padding-left: 0;
  margin-left:0;
 width: 100%; 
  
}

nav li {
  background-color: #ffffff;
   list-style: none;
   border: 1px solid black;
  padding: .25em;
  margin: 0;
  font-size: 1em;
}


.main-section {
  display: inline-block;
}


li {
 margin-left: 2em; 
  font-size: 1em;
}
  
  
}












/*********************************************************
@media screen and(min-width:769px){
#header {
  display: inline;
  width: 24%;
}

nav {
  display:inline-flex;
  width: 24%;
}

#nav-bar {
  display:inline-flex;
  flex-direction: column;
 
  z-index: 25;
}

nav ul {
display: inline-block;
 padding-left: 0;
 width: 24%; 
  
}

.main-section {
  display: inline-block;
  float: right;
}
  
  }*/

              
            
!

JS

              
                
              
            
!
999px

Console