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

              
                <!DOCTYPE html>
<html>
	<head>
		<head>
		<meta charset="UTF-8">
		<title>CSS Flexible Box Layout</title>
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
		<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
	</head>

<body>
		<div id="container">
			<nav id="navbar">
				<header id="navbar-header"><i class="fab fa-css3-alt"></i>CSS Flexbox</header>
				<ul>
					<li><a href="#Introduction" class="nav-link">Introduction</a></li>
					<li><a href="#The_two_axes_of_flexbox" class="nav-link">The two axes of flexbox</a></li>
					<li><a href="#Start_and_end_lines" class="nav-link">Start and end lines</a></li>
					<li><a href="#The_flex_container" class="nav-link">The flex container</a></li>

          <li><a href="#Multi-line_flex_containers_with_flex-wrap" class="nav-link">Multi-line flex containers with flex-wrap</a></li>
					<li><a href="#The_flex-flow_shorthand" class="nav-link">The flex-flow shorthand</a></li>
					<li><a href="#Properties_applied_to_flex_items" class="nav-link">Properties applied to flex items</a></li>
					<li><a href="#Alignment,_justification_and_distribution_of_free_space_between_items" class="nav-link">Alignment, justification and distribution of free space between items</a></li>
					<li><a href="#Next_steps" class="nav-link">Next steps</a></li>
				</ul>
			</nav>
			<main id="main-doc">
        <header></header>
        <h1>CSS Flexible Box Layout</h1>
        <h2>Basic concepts of flexbox</h2>
        </header>
<!-- Section 1 Introduction-->
				<section id="Introduction" class="main-section">
					<header>
						<h2>Introduction</h2>
					</header>
						<article>
						<p>CSS Flexible Box Layout is a module of CSS that defines a CSS box model optimized for user interface design, and the layout of items in one dimension. In the flex layout model, the children of a flex container can be laid out in any direction, and can “flex” their sizes, either growing to fill unused space or shrinking to avoid overflowing the parent. Both horizontal and vertical alignment of the children can be easily manipulated.</p>
						<h3>Basic Example</h3>
						<p>In the following example a container has been set to display: flex, which means that the three child items become flex items. The value of justify-content has been set to space-between in order to space the items out evenly on the main axis. An equal amount of space is placed between each item with the left and right items being flush with the edges of the flex container. You can also see that the items are stretching on the cross axis, due to the default value of align-items being stretch. The items stretch to the height of the flex container, making them each appear as tall as the tallest item.</p>
						<div id="box1" class="box-example">
										<div class="boxA">One</div>
										<div class="boxB">Two</div>
										<div class="boxC">Three
																 <br>has
																 <br>extra
																 <br>text	
									  </div>		
									</div>
						<div class="code">
							<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
	display: flex;
	justify-content: space-between;
}
</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv &gtOne&lt/div&gt
	&ltdiv &gtTwo&lt/div&gt
	&ltdiv &gtThree
          &ltbr&gthas
          &ltbr&gtextra
          &ltbr&gttext	
	&lt/div&gt		
&lt/div&gt  
</code>
</pre>
	                   
	                    
					     </div>
	                <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>
									<div class="back-to-menu">
									<h3><a href="#navbar">Back to menu</a></h3>
									</div>
				    </article>
				</section>
<!-- Section 2 The two axes of flexbox-->					
				<section id="The_two_axes_of_flexbox" class="main-section">
					<header>
						<h2>The two axes of flexbox</h2>
					</header>
						<article>
						<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 class="tag" 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>
						<h3>The main axis</h3>
						<p>The main axis is defined by <span class="tag">flex-direction</span>, which has four possible values:</p>
						<ul>
							<li><span class="tag">row</span></li>
							<li><span class="tag">row-reverse</span></li>
							<li><span  class="tag">column</span></li>
							<li><span class="tag">column-reverse</span></li>
						</ul>
						<p>Should you choose <span class="tag">row</span> or <span class="tag">row-reverse</span>, your main axis will run along the row in the <strong>inline direction</strong>.</p>
						<img src="https://mdn.mozillademos.org/files/15614/Basics1.png" alt="Main Axis - flex-direction: row">
						<p>Choose <span class="tag">column</span> or <span class="tag">column-reverse</span> and your main axis will run from the top of the page to the bottom — in the <strong>block direction</strong>.</p>
						<img src="https://mdn.mozillademos.org/files/15615/Basics2.png" alt="Main Axis - flex-direction: column">
						<h3>The cross axis</h3>
						<p>The cross axis runs perpendicular to the main axis, therefore if your <span class="tag">flex-direction</span> (main axis) is set to <span class="tag">row</span> or <span class="tag">row-reverse</span> the cross axis runs down the columns.</p>
						<img src="https://mdn.mozillademos.org/files/15616/Basics3.png" alt="Cross Axis - flex-direction: row">
						<p>If your main axis is <span class="tag">column</span> or <span class="tag">column-reverse</span> then the cross axis runs along the rows.</p>
						<img src="https://mdn.mozillademos.org/files/15617/Basics4.png" alt="Cross Axis - flex-direction: column">
						<p>Understanding which axis is which is important when we start to look at aligning and justifying flex items; flexbox features properties that align and justify content along one axis or the other.</p>
					</article>
				</section>
<!-- Section 3 Start and end lines-->
				<section id="Start_and_end_lines" class="main-section">
					<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 <span class="tag">flex-direction</span> 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>
						<img src="https://mdn.mozillademos.org/files/15618/Basics5.png" alt="Main Axis - flex-direction: row">
						<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>
						<img src="https://mdn.mozillademos.org/files/15619/Basics6.png" alt="Main Axis - flex-direction: row">
						<p>In both cases the start edge of the cross axis is at the top of the flex container and the end edge at the bottom, as both languages have a horizontal writing mode.</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>
						<div class="back-to-menu">
							<h3><a href="#navbar">Back to menu</a></h3>
						</div>
					</article>
				</section>
<!-- Section 4 The flex container-->   
				<section id="The_flex_container" class="main-section">
					<header>
            			<h2>The flex container</h2>
					</header>
						<article>
						<p>An area of a document laid out using flexbox is called a <strong>flex container</strong>. To create a flex container, we set the value of the area's container's <a class="tag" href="https://developer.mozilla.org/en-US/docs/Web/CSS/display"  target="_blank">display</a> property to <span class="tag">flex</span> or <span class="tag">inline-flex</span>. As soon as we do this the direct children of that container become <strong>flex items</strong>. 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>
						<ul>
							<li>Items display in a row (the <span class="tag">flex-direction</span> property's default is <span class="tag">row</span>).</li>
							<li>The items start from the start edge of the main axis.</li>
							<li>The items start from the start edge of the main axis.</li>
							<li>The items will stretch to fill the size of the cross axis.</li>
							<li>The <a class="tag" href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis" target="_blank">flex-basis</a> property is set to <span class="tag">auto</span>.</li>
							<li>The <a class="tag" href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap" target="_blank">flex-wrap</a> property is set to <span class="tag">nowrap</span>.</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>
						<p>You can see in the live example below how this looks. Try editing the items or adding additional items in order to test the initial behavior of flexbox.</p>
						<div id="box2" class="box-example">
										<div class="boxA">One</div>
										<div class="boxB">Two</div>
										<div class="boxC">Three
																 <br>has
																 <br>extra
																 <br>text	
									  </div>		
									</div>
						<div class="code">
							<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
	display: flex;
}
</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv &gtOne&lt/div&gt
	&ltdiv &gtTwo&lt/div&gt
	&ltdiv &gtThree
          &ltbr&gthas
          &ltbr&gtextra
          &ltbr&gttext	
	&lt/div&gt		
&lt/div&gt   
</code>
</pre>                    
					     </div>
							<div class="back-to-menu">
							<h3><a href="#navbar">Back to menu</a></h3>
							</div>
				    </article>
				</section>
<!-- Section 5 Multi-line flex containers with flex-wrap -->	
				<section id="Multi-line_flex_containers_with_flex-wrap" class="main-section">
					<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 class="tag" href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap" target="_blank">flex-wrap</a> with a value of <span class="tag">wrap</span>. 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 <span class="tag">flex-wrap</span> is set to <span class="tag">wrap</span>, the items wrap. Set it to <span class="tag">nowrap</span>, 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 <span class="tag">nowrap</span> would cause an overflow if the items were not able to shrink, or could not shrink small enough to fit.</p>
						<div id="box3" class="box-example">
							<div class="boxA">One</div>
							<div class="boxB">Two</div>
							<div class="boxC">Three</div>		
						</div>

						<div class="code">
							<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
	display: flex;
	flex-wrap: wrap;
}
</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv&gtOne&lt/div&gt
	&ltdiv&gtTwo&lt/div&gt
	&ltdiv&gtThree&lt/div&gt		
&lt/div&gt   
</code>
</pre>
	                   
	                    
					     </div>
					     <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>
						<div class="back-to-menu">
						<h3><a href="#navbar">Back to menu</a></h3>
						</div>
				    </article>
				</section>
<!-- Section 6 The flex-flow shorthand -->				
				<section id="The_flex-flow_shorthand" class="main-section">
					<header>
            			<h2>The flex-flow shorthand</h2>
					</header>
						<article>
						<p>You can combine the two properties <span class="tag">flex-direction</span> and <span class="tag">flex-wrap</span> into the <a class="tag" href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-flow" target="_blank">flex-flow</a> shorthand. The first value specified is <span class="tag">flex-direction</span> and the second value is <span class="tag">flex-wrap</span>.</p>
						<div id="box4" class="box-example">
							<div class="boxA">One</div>
							<div class="boxB">Two</div>
							<div class="boxC">Three</div>		
						</div>

						<div class="code">
							<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
	display: flex;
	flex-flow: row wrap;
}
</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv&gtOne&lt/div&gt
	&ltdiv&gtTwo&lt/div&gt
	&ltdiv&gtThree&lt/div&gt		
&lt/div&gt   
</code>
</pre>
					</div>
						<div class="back-to-menu">
						<h3><a href="#navbar">Back to menu</a></h3>
						</div>
				    </article>
				</section>
<!-- Section 7 Properties applied to flex items -->					
				<section id="Properties_applied_to_flex_items" class="main-section">
					<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" class="tag" target="_blank">flex-grow</a></li>
							<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink" class="tag" target="_blank">flex-shrink</a></li>
							<li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis" class="tag" target="_blank">flex-basis</a></li>
						</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 <strong>available space</strong>. 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>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>
						<img src="https://mdn.mozillademos.org/files/15620/Basics7.png" alt="Available space vs container space">
						<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>
						<h3>The <span class="tag">flex-basis</span> property</h3>
						<p>The <span class="tag">flex-basis</span> is what defines the size of that item in terms of the space it leaves as available space. The initial value of this property is <span class="tag">auto</span> — in this case the browser looks to see if the items have a size. In the example above, all of the items have a width of 100 pixels and so this is used as the <span class="tag">flex-basis</span>.</p>
						<p>If the items don’t have a size then the content's size is used as the flex-basis. This is why when we just declare <span class="tag">display: flex</span> on the parent to create flex items, the items all move into a row and take only as much space as they need to display their contents.</p>
						<h3>The <span class="tag">flex-grow</span> property</h3>
						<p>With the <span class="tag">flex-grow</span> property set to a positive integer, flex items can grow along the main axis from their <span class="tag">flex-basis</span>. This will cause the item to stretch and take up any available space on that axis, or a proportion of the available space if other items are allowed to grow too.</p>
						<p>If we gave all of our items in the example above a flex-grow value of 1 then the available space in the flex container would be equally shared between our items and they would stretch to fill the container on the main axis.</p>
						<p>The <span class="tag">flex-grow</span> property can be used to distribute space in proportion. If we give our first item a <span class="tag">flex-grow</span> value of 2 and the other items a value of 1, 2 parts will be given to the first item (100px out of 200px in the case of the example above), 1 part each the other two (50px each out of the 200px total).</p>
						<h3>The <span class="tag">flex-shrink</span> property</h3>
						<p>Where the <span class="tag">flex-grow</span> property deals with adding space in the main axis, the <span class="tag">flex-shrink</span> property controls how it is taken away. If we do not have enough space in the container to lay out our items and <span class="tag">flex-shrink</span> is set to a positive integer the item can become smaller than the <span class="tag">flex-basis</span>. As with <span class="tag">flex-grow</span> different values can be assigned in order to cause one item to shrink faster than others — an item with a higher value set for <span class="tag">flex-shrink</span> will shrink faster than its siblings that have lower values.</p>
						<p>The minimum size of the item will be taken into account while working out the actual amount of shrinkage that will happen, which means that flex-shrink has the potential to appear less consistent than flex-grow in behavior. We’ll therefore take a more detailed look at how this algorithm works in the article Controlling Ratios of items along the main axis.</p>
						<div class="note">
							<p><i class="fas fa-clipboard"></i> Note that these values for <span class="tag">flex-grow</span> and <span class="tag">flex-shrink</span> are proportions. Typically if we had all of our items set to flex: <span class="tag">1 1 200px</span> and then wanted one item to grow at twice the rate, we would set that item to <span class="tag">flex: 2 1 200px</span>. However you could use flex: <span class="tag">10 1 200px</span> and flex: <span class="tag">20 1 200px</span> if you wanted.</p>
						</div>
						<h3>Shorthand values for the flex properties</h3>
						<p>You will very rarely see the <span class="tag">flex-grow</span>, <span class="tag">flex-shrink</span>, and <span class="tag">flex-basis</span> properties used individually; instead they are combined into the <span class="tag">flex</span> shorthand. The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/flex" class="tag" target="_blank">flex</a> shorthand allows you to set the three values in this order — <span class="tag">flex-grow</span>, <span class="tag">flex-shrink</span>, <span class="tag">flex-basis</span>.</p>
						<p>The example below allows you to test out the different values of the flex shorthand; remember that the first value is <span class="tag">flex-grow</span>. Giving this a positive value means the item can grow. The second is <span class="tag">flex-shrink</span> — with a positive value the items can shrink, but only if their total values overflow the main axis. The final value is <span class="tag">flex-basis</span>; this is the value the items are using as their base value to grow and shrink from.</p>




						<div id="box5" class="box-example">
							<div class="child5-1 boxA">One</div>
							<div class="child5-2 boxB">Two</div>
							<div class="child5-3 boxC">Three</div>		
						</div>

						<div class="code">
							<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
        display: flex;
      }

      .one {
        flex: 1 1 auto;
      }

      .two {
        flex: 1 1 auto;
      }

      .three {
        flex: 1 1 auto;
      }
</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv&gtOne&lt/div&gt
	&ltdiv&gtTwo&lt/div&gt
	&ltdiv&gtThree&lt/div&gt		
&lt/div&gt   
</code>
</pre>
					</div>
					<p>There are also some predefined shorthand values which cover most of the use cases. You will often see these used in tutorials, and in many cases these are all you will need to use. The predefined values are as follows:</p>
					<ul>
						<li><span class="tag">flex: initial</span></li>
						<li><span class="tag">flex: auto</span></li>
						<li><span class="tag">flex: none</span></li>
						<li><span class="tag">flex: &ltpositive-number&gt</span></li>
					</ul>
					<p>Setting <span class="tag">flex: initial</span> resets the item to the initial values of Flexbox. This is the same as <span class="tag">flex: 0 1 auto</span>. In this case the value of <span class="tag">flex-grow</span> is 0, so items will not grow larger than their <span class="tag">flex-basis</span> size. The value of <span class="tag">flex-shrink</span> is 1, so items can shrink if they need to rather than overflowing. The value of <span class="tag">flex-basis</span> is <span class="tag">auto</span>. Items will either use any size set on the item in the main dimension, or they will get their size from the content size.</p>
					<p>Using <span class="tag">flex: auto</span> is the same as using <span class="tag">flex: 1 1 auto</span>; everything is as with flex:initial but in this case the items can grow and fill the container as well as shrink if required.</p>
					<p>Using <span class="tag">flex: none</span> will create fully inflexible flex items. It is as if you wrote <span class="tag">flex: 0 0 auto</span>. The items cannot grow or shrink but will be laid out using flexbox with a <span class="tag">flex-basis</span> of <span class="tag">auto</span>.</p>
					<p>The shorthand you often see in tutorials is <span class="tag">flex: 1</span> or <span class="tag">flex: 2</span> and so on. This is as if you used <span class="tag">flex: 1 1 0</span>. The items can grow and shrink from a <span class="tag">flex-basis</span> of 0.</p>
					<p>Try these shorthand values in the example below.</p>

					
					<div id="box6" class="box-example">
							<div class="child6-1 boxA">One</div>
							<div class="child6-2 boxB">Two</div>
							<div class="child6-3 boxC">Three</div>		
					</div>

					<div class="code">
						<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
  display: flex;
}

.one {
  flex: 1;
}

.two {
  flex: 1;
}

.three {
  flex: 1;
}
  
</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv&gtOne&lt/div&gt
	&ltdiv&gtTwo&lt/div&gt
	&ltdiv&gtThree&lt/div&gt		
&lt/div&gt   
</code>
</pre>
					</div>


						<div class="back-to-menu">
						<h3><a href="#navbar">Back to menu</a></h3>
						</div>
				    </article>
				</section>
<!-- Section 8 Alignment, justification and distribution of free space between items -->
				
				<section id="Alignment,_justification_and_distribution_of_free_space_between_items" class="main-section">
					<header>
            			<h2>Alignment, justification and distribution of free space between items</h2>
					</header>
						<article>
						<p>A key feature of flexbox is the ability to align and justify items on the main- and cross-axes, and to distribute space between flex items.</p>
						<h3><span class="tag">align-items</span></h3>
						<p>The <a class="tag" href="https://developer.mozilla.org/en-US/docs/Web/CSS/align-items" target="_blank">align-items</a> property will align the items on the cross axis.</p>
						<p>The initial value for this property is <span class="tag">stretch</span> 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.</p>
						<p>You could instead set <span class="tag">align-items</span> to <span class="tag">flex-start</span> in order to make the items line up at the start of the flex container, <span class="tag">flex-end</span> to align them to the end, or <span class="tag">center</span> 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><span class="tag">stretch</span></li>
							<li><span class="tag">flex-start</span></li>
							<li><span class="tag">flex-end</span></li>
							<li><span class="tag">center</span></li>
						</ul>

						<div id="box7" class="box-example">
							<div class="boxA">One</div>
							<div class="boxB">Two</div>
							<div class="boxC">Three</div>		
						</div>

						<div class="code">
							<i class="fas fa-file-code"></i>
<pre>
<code>
.box {
  display: flex;
  align-items: flex-start;
}

</code>
</pre>
			         </div>
					  <div class="code">
					       <i class="fas fa-file-code"></i>
             	
<pre>
<code>
&ltdiv class="box"&gt
	&ltdiv&gtOne&lt/div&gt
	&ltdiv&gtTwo&lt/div&gt
	&ltdiv&gtThree&lt/div&gt		
&lt/div&gt   
</code>
</pre>
					</div>
					<h3><span class="tag">justify-content</span></h3>
					<p>The <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content" class="tag" target="_blank">justify-content</a> property is used to align the items on the main axis, the direction in which <span class="tag">flex-direction</span> has set the flow. The initial value is <span class="tag">flex-start</span> which will line the items up at the start edge of the container, but you could also set the value to <span class="tag">flex-end</span> to line them up at the end, or <span class="tag">center</span> to line them up in the centre.</p>
					<p>You can also use the value <span class="tag">space-between</span> 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 <span class="tag">space-around</span>. With <span class="tag">space-around</span>, items have a half-size space on either end. Or, to cause items to have equal space around them use the value <span class="tag">space-evenly</span>. With <span class="tag">space-evenly</span>, items have a full-size space on either end.</p>



						<div class="back-to-menu">
						<h3><a href="#navbar">Back to menu</a></h3>
						</div>
				    </article>
				</section>
				<!-- Section 9 Next steps -->
				<section id="Next_steps" class="main-section">
					<header>
            			<h2>Next steps</h2>
					</header>
						<article>
						<p>After reading this article you should have an understanding of the basic features of Flexbox. In the next article we will look at <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Relationship_of_Flexbox_to_Other_Layout_Methods" target="_blank">how this specification relates to other parts of CSS</a>.</p>
						<div class="back-to-menu">
						<h3><a href="#navbar">Back to menu</a></h3>
						</div>
				    </article>
				</section>

			</main>
		</div>
		<footer>
      <div>
      <p>All the documentation in this page is taken from <a href="https://developer.mozilla.org/es/docs/Web/CSS/CSS_Flexible_Box_Layout" class="tag" target="_blank">MDN</a>
      </div>
    </footer>
	</body>
</html>

<!-- 

Hello Camper!

For now, the test suite only works in Chrome! Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

-->

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Inconsolata|Montserrat:400,400i,700');

/* Gereral style */
* { margin: 5px;
	padding: 5px;
	box-sizing: border-box;

}
body {
	font-family: 'Montserrat', sans-serif;
}

h1  {
 color: #f05d23;
 text-decoration: underline;
 text-align: center;
}
h2,h3 {
	color: #260c1a;
}
p {
text-align: justify;
}
img {
	margin: auto;
}

a {
	color: #260c1a;

}
a:hover {
	color: #f05d23;

}

a:visited {
	color: #f05d23;
} 

.tag {
	background: #260c1a;
	color: #f7f7f2;
	padding: 1px;
}
#container {
	background: #f7f7f2;
	display: flex;
}

/* Navbar style */
	#navbar {
		background: #260c1a;
		color: #c5d86d;
    	align-self: stretch;
		width: 20%;
	}
	
		.nav-link {
      color: #f7f7f2;
		}
		nav ul {
			list-style: none;
			padding: 0;
		}
		nav a {
			text-decoration: none;
		}
	/* main-doc style */
	#main-doc {
		margin-left: 25%;
	}

			.code {
				background: #c5d86d;
				border-left: 5px solid;
				border-color: #f05d23;
				width: 450px;
				margin: 10px auto;
				text-align: left;
				align-self: center;
        font-family: 'Inconsolata', monospace;
			}
			.note {
				border-left: 5px solid;
				border-color: #f05d23;
				width: 450px;
				margin: 10px auto;
			}
/* aparence of each example box */
			.box-example {
				background: #c5d86d;
				width: 450px;
				margin: 10px auto;
				border: 2px solid;
				border-color: #f05d23;
				align-self: center;
			}
				/* flex configuration example boxes */
				#box1 {
					display: flex;
					justify-content: space-between;
        		}
        		#box2 {
					display: flex;
        		} 
        		#box3 {
					display: flex;
					flex-wrap: wrap;
				}	
				#box4 {
					display: flex;
					flex-flow: row wrap;
				}	
				#box5 {
					display: flex;
				}
				/* flex-property for child-box  */
				.child5-1 {
					flex: 1 1 auto;
				}	
				.child5-2 {
					flex: 1 1 auto;
				}	
				.child5-3 {
					flex: 1 1 auto;
				}
				#box6 {
					display: flex;
				}	
					.child6-1 {
					flex: 1;
				}	
				.child6-2 {
					flex: 1;
				}	
				.child6-3 {
					flex: 1;
				}
				#box7 {
					display: flex;
					justify-content: flex-start;
				}	

				/* background color for the 3 example child-boxes */
				.boxA {
					background: #260c1a;
					color: #f7f7f2;
				}
				.boxB {
					background: #f05d23;
				}
				.boxC {
					background: #f7f7f2;
				}
				.back-to-menu {
					display: none;
				}
/* footer style */	
footer {
background: #f7f7f2;
margin-left: 25%;
}

@media all and (max-width: 500px)  {
	#container {
		display:flex;
		flex-direction: column;
	}
	#navbar {
		position: block;
		width: 100%;
	}
	#main-doc {
		margin-left: 0;
	}
	.back-to-menu {
		display: block;
	}
  .note {
		width: auto;
		font-size: 10px;	
	}
	.code {
		width: auto;
		font-size: 10px;	
	}
	.box-example {
			width: auto;
			font-size: 10px;
	}
  footer {
    margin-left: 1em;
  }
}
@media all and (min-width: 500px) {
		#navbar {
		position: fixed;
	}
}


              
            
!

JS

              
                // !! IMPORTANT README:

// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place. 

/***********
INSTRUCTIONS:
  - Select the project you would 
    like to complete from the dropdown 
    menu.
  - Click the "RUN TESTS" button to
    run the tests against the blank 
    pen.
  - Click the "TESTS" button to see 
    the individual test cases. 
    (should all be failing at first)
  - Start coding! As you fulfill each
    test case, you will see them go   
    from red to green.
  - As you start to build out your 
    project, when tests are failing, 
    you should get helpful errors 
    along the way!
    ************/

// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!

// Once you have read the above messages, you can delete all comments. 

              
            
!
999px

Console