<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ flexbox - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ flexbox - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 10:49:22 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/flexbox/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Use Flex in Tailwind CSS and Justify Flex Items ]]>
                </title>
                <description>
                    <![CDATA[ Hey there! If you're building modern web interfaces, chances are you've already fallen in love with Tailwind CSS for its speed and flexibility. One of the most powerful tools in Tailwind's arsenal is  ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-flex-in-tailwind-css-and-justify-flex-items/</link>
                <guid isPermaLink="false">69b1975b6c896b0519a78b21</guid>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tailwind CSS Tutorial ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tailwind ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Flex ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flex css ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ajay Patel ]]>
                </dc:creator>
                <pubDate>Wed, 11 Mar 2026 16:24:59 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/3522007b-55f0-44bf-9b6f-b0489d1a8774.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hey there! If you're building modern web interfaces, chances are you've already fallen in love with Tailwind CSS for its speed and flexibility.</p>
<p>One of the most powerful tools in Tailwind's arsenal is its set of Flexbox utilities. Flexbox lets you create dynamic, responsive layouts without writing custom CSS, and Tailwind makes it incredibly intuitive with simple class names.</p>
<p>In this tutorial, we'll walk through everything you need to know about using Flexbox in Tailwind, from the basics to advanced patterns. Whether you're a beginner or looking to level up your layouts, by the end, you'll feel confident building anything from card grids to complex dashboards.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="https://preview.freecodecamp.org/69857b45ac030cc5d597ac21#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a href="#heading-what-is-flexbox">What is Flexbox?</a></p>
</li>
<li><p><a href="#heading-how-tailwind-css-makes-flexbox-easy-to-use">How Tailwind CSS Makes Flexbox Easy to Use</a></p>
</li>
<li><p><a href="#heading-how-to-use-flex-in-tailwind">How to use flex in Tailwind</a></p>
</li>
<li><p><a href="#heading-flex-item-sizing-basis-grow-amp-shrink">Flex Item Sizing: Basis, Grow &amp; Shrink</a></p>
</li>
<li><p><a href="#heading-controlling-flex-direction">Controlling Flex Direction</a></p>
</li>
<li><p><a href="#heading-fine-tuning-flexbox-layout">Fine-Tuning Flexbox Layout</a></p>
</li>
<li><p><a href="#heading-how-to-justify-and-align-flex-items-in-tailwind">How to Justify and Align Flex Items in Tailwind</a></p>
</li>
<li><p><a href="#heading-practice-flexbox-with-interactive-games">Practice Flexbox with Interactive Games</a></p>
</li>
<li><p><a href="#heading-conclusion">Conclusion:</a></p>
</li>
</ul>
<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<p>Before diving into Flexbox with Tailwind CSS, it helps to have a few basics in place so you can follow along comfortably.</p>
<p><strong>Basic Knowledge:</strong></p>
<ul>
<li><p>A foundational understanding of <strong>HTML</strong> (how elements and containers work).</p>
</li>
<li><p>Basic familiarity with <strong>CSS</strong> (especially properties like <code>display</code>, <code>width</code>, and <code>height</code>).</p>
</li>
<li><p>A general idea of how responsive design works (helpful but not required).</p>
</li>
</ul>
<p>You do <em>not</em> need to be a Flexbox expert, as we’ll cover the important concepts as we go.</p>
<p><strong>Tools You’ll Need:</strong></p>
<ul>
<li><p>A code editor like VS Code (or any editor you prefer)</p>
</li>
<li><p>A browser for testing layouts</p>
</li>
<li><p>A project with Tailwind CSS installed</p>
</li>
</ul>
<h2 id="heading-what-is-flexbox">What is Flexbox?</h2>
<p><strong>Flexbox (Flexible Box Layout)</strong> is a CSS layout model designed to make it easier to design flexible, responsive layouts without using floats or complicated positioning tricks.</p>
<p>Before Flexbox, aligning elements vertically, spacing items evenly, or making layouts adapt to different screen sizes was often frustrating and required hacks. Flexbox solves these problems by providing a simple and predictable way to control alignment, spacing, and ordering of elements inside a container.</p>
<p>The main concept is simple:</p>
<ul>
<li><p>You have a flex container</p>
</li>
<li><p>Inside it are flex items</p>
</li>
<li><p>The container controls how its items are laid out</p>
</li>
</ul>
<p>Once an element is set to <code>display: flex</code>, its children automatically become flex items.</p>
<pre><code class="language-css">.container {
  display: flex;
}
</code></pre>
<h2 id="heading-how-tailwind-css-makes-flexbox-easy-to-use">How Tailwind CSS Makes Flexbox Easy to Use</h2>
<p>Flexbox is powerful, but writing custom CSS for every layout can become repetitive and time-consuming. Tailwind CSS simplifies this by providing utility classes that map directly to Flexbox properties, allowing developers to build layouts quickly without writing custom CSS.</p>
<p>Instead of switching between HTML and CSS files, Tailwind lets you apply Flexbox behavior directly in your markup, making layouts more readable and faster to develop. It turns Flexbox's sometimes verbose properties into short, memorable utilities. No more remembering <code>justify-content: space-between;</code> just write <code>justify-between</code>.</p>
<p>Benefits:</p>
<ul>
<li><p>Responsive by default (add <code>md:</code>, <code>lg:</code>, and so on)</p>
</li>
<li><p>Composable (combine classes freely).</p>
</li>
<li><p>No custom CSS needed for most cases.</p>
</li>
</ul>
<h2 id="heading-how-to-use-flex-in-tailwind">How to Use Flex in Tailwind</h2>
<p>Flexbox is one of the most powerful layout systems in modern CSS, and Tailwind CSS makes it extremely approachable by exposing Flexbox behavior through simple utility classes. Instead of writing custom CSS, you compose layouts directly in your HTML using predefined classes.</p>
<ol>
<li><p><code>flex</code>: The <code>flex</code> Class is the foundation of Flexbox in Tailwind.</p>
</li>
<li><p><code>flex-1</code>: Allows the element to grow and shrink and forces it to take up the remaining available space.</p>
</li>
<li><p><code>flex-auto</code>: It makes an item flexible while respecting its content size – that is, it only grows and shrinks as needed.</p>
</li>
<li><p><code>flex-none</code>: Disables growing and shrinking for an item.</p>
</li>
</ol>
<p>Here is a basic example that shows where to place these classes:</p>
<pre><code class="language-xml">&lt;!-- this is the container --&gt;
&lt;div class="flex"&gt;
  &lt;!-- these are the items inside the container --&gt;
  &lt;div class="flex-1"&gt;Item 1&lt;/div&gt;
  &lt;div class="flex-auto"&gt;Item 2&lt;/div&gt;
  &lt;div class="flex-none"&gt;Item 3&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<h2 id="heading-flex-item-sizing-basis-grow-amp-shrink">Flex Item Sizing: Basis, Grow, &amp; Shrink</h2>
<p>Three fundamental properties control how elements size themselves inside a flex container:</p>
<ul>
<li><p>flex-basis</p>
</li>
<li><p>flex-grow</p>
</li>
<li><p>flex-shrink</p>
</li>
</ul>
<p>Rather than thinking in fixed widths and heights, Flexbox uses a dynamic space-distribution model. Each flex item starts with an initial size, then grows or shrinks depending on the available space and the rules defined by these three properties.</p>
<h3 id="heading-flex-basis">flex-basis</h3>
<p><a href="https://tailwindcss.com/docs/flex-basis">flex-basis</a> controls the initial size of a flex item before <code>flex-grow</code> or <code>flex-shrink</code> kick in. Think of it as the item’s starting width or height (depending on flex direction).</p>
<pre><code class="language-xml">&lt;div class="flex ..."&gt;
	&lt;div class="... basis-1/5"&gt;01&lt;/div&gt;
  &lt;div class="...basis-4/5"&gt;02&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Here's what this makes:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770355749158/19071bac-8426-4602-a7ab-fcc0ecd62c95.png" alt="flex basis" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>flex-basis's most used utility classes are:</p>
<ul>
<li><p><code>basis-auto</code>: This means the item’s initial size is based on its <strong>content size or any explicitly defined width/height</strong>. It doesn't force a specific starting size. Instead, it respects intrinsic sizing.</p>
</li>
<li><p><code>basis-0</code>: This makes the item start at <strong>0 width (or height in column layouts)</strong> before space is distributed. It’s commonly used with <code>grow</code> to evenly distribute space regardless of content size.</p>
</li>
<li><p><code>basis-full</code>: The item initially takes up the <strong>entire width (or height)</strong> of the container before shrinking or wrapping.</p>
</li>
<li><p><code>basis-xs/md/lg/xl..</code>: Built-in values.</p>
</li>
<li><p><code>basis-&lt;fraction&gt;</code>: Giving a value with a dynamic such as 1/2, 4/5, and so on.</p>
</li>
<li><p><code>basis-&lt;number&gt;</code>: Uses Tailwind’s spacing scale (in <code>rem</code> units).</p>
</li>
<li><p><code>basis-[&lt;value&gt;]</code>: Syntax to set the basis based on a completely custom value.</p>
</li>
</ul>
<h3 id="heading-flex-grow">flex-grow</h3>
<p><a href="https://tailwindcss.com/docs/flex-grow">flex-grow</a> controls how much a flex item expands to fill extra space in the flex container. It determines how leftover space is distributed among flex items after their initial sizes.</p>
<pre><code class="language-xml">&lt;div class="flex ..."&gt;
	&lt;div class="... grow"&gt;01&lt;/div&gt;
  &lt;div class="...grow-0"&gt;02&lt;/div&gt;
  &lt;div class="...grow"&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Here's what this creates:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770355790996/6c4f3c72-0ff9-4f5c-bab7-6e5bc1e9df2e.png" alt="flex grow" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>flex-grow's most used utility classes are:</p>
<ul>
<li><p><code>grow</code>: The item will grow to take up available extra space. If multiple items use <code>grow</code>, they share space equally (unless different grow values are specified)..</p>
</li>
<li><p><code>grow-0</code>: The item will <strong>not expand</strong> beyond its initial size, even if extra space is available.</p>
</li>
<li><p><code>grow-&lt;number&gt;</code>: If one item has <code>grow-2</code> and another has <code>grow-1</code>, the first item gets <strong>twice as much extra space</strong> as the second.</p>
</li>
<li><p><code>grow-[&lt;value&gt;]</code>: Allows a custom grow value (e.g. grow-[3]).</p>
</li>
</ul>
<h3 id="heading-flex-shrink">flex-shrink</h3>
<p><a href="https://tailwindcss.com/docs/flex-shrink">flex-shrink</a> controls how much a flex item shrinks when there isn’t enough space in the flex container. It determines how items reduce their size relative to each other when the container overflows.</p>
<pre><code class="language-xml">&lt;div class="flex ..."&gt;
	&lt;div class="... grow shrink-0"&gt;01&lt;/div&gt;
  &lt;div class="...shrink"&gt;02&lt;/div&gt;
  &lt;div class="...grow shrink-0"&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Here's what this creates:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770355844387/bd1b9e5c-0ae5-4e61-97f7-2cbfbc060ecf.png" alt="flex shrink" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>flex-shrink's most used utility classes are:</p>
<ul>
<li><p><code>shrink</code>: The item is allowed to shrink when necessary to prevent overflow.</p>
</li>
<li><p><code>shrink-0</code>: The item will <strong>not shrink</strong>, even if space becomes limited. This may cause overflow if other items cannot compensate.</p>
</li>
<li><p><code>shrink-&lt;number&gt;</code>: Sets proportional shrinking behavior. An item with <code>shrink-2</code> will shrink <strong>twice as much</strong> as one with <code>shrink-1</code>.</p>
</li>
<li><p><code>shrink-[&lt;value&gt;]</code>: Syntax to set a completely custom shrink value.</p>
</li>
</ul>
<h2 id="heading-controlling-flex-direction">Controlling Flex Direction</h2>
<p>In Tailwind CSS, the direction in which flex items are laid out is controlled using <a href="https://tailwindcss.com/docs/flex-direction">flex-direction utilities</a>. These utilities define whether items are placed horizontally or vertically, and in which order.</p>
<h3 id="heading-flex-row">flex-row</h3>
<p><code>flex-row</code> is the default flex direction in both CSS Flexbox and Tailwind. When it is applied, flex items are laid out <strong>horizontally</strong> along the main axis, starting from left to right (in left-to-right languages).</p>
<pre><code class="language-xml">&lt;div class="flex flex-row"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>This outputs:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770356616341/4b3dbd4c-e437-49d0-a9b5-0576781ccfc3.png" alt="flex row default" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Use case:</strong> Navigation bars, horizontal button groups, toolbars.</p>
<h3 id="heading-flex-row-reverse">flex-row-reverse</h3>
<p>The <code>flex-row-reverse</code> utility lays out flex items horizontally, but in the opposite direction from right to left. While the visual order of items is reversed, the HTML source order remains unchanged, which is important for accessibility and screen readers.</p>
<pre><code class="language-xml">&lt;div class="flex flex-row-reverse"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>Output:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770356916275/1fad634a-c4a0-4417-a63e-0ed51d9f76f7.png" alt="flex row reverse" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Use case:</strong> Forms, cards, sidebars, vertical menus.</p>
<h3 id="heading-flex-col">flex-col</h3>
<p>The <code>flex-col</code> utility changes the flex direction to <strong>vertical</strong>, stacking items from top to bottom. In this case, the main axis runs vertically.</p>
<pre><code class="language-html">&lt;div class="flex flex-col"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt; 
</code></pre>
<p>Output:</p>
<img src="https://cdn.hashnode.com/uploads/covers/5e0f2c2e490269cb30227a2b/cea4e846-a234-42e8-9509-2b166a5cf5c4.png" alt="cea4e846-a234-42e8-9509-2b166a5cf5c4" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Use case:</strong> Forms, cards, sidebars, vertical menus.</p>
<h3 id="heading-flex-col-reverse">flex-col-reverse</h3>
<p>In <code>flex-col-reverse</code>, items are stacked vertically, but in <strong>reverse order</strong>, starting from bottom to top (that is, vertically reverse order).</p>
<pre><code class="language-xml">&lt;div class="flex flex-col-reverse"&gt;
  &lt;div&gt;01&lt;/div&gt;
  &lt;div&gt;02&lt;/div&gt;
  &lt;div&gt;03&lt;/div&gt;
&lt;/div&gt; 
</code></pre>
<p>Here's the output:</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357355380/9d2d03b9-0c23-4360-ab82-2ccf8c1f32d9.png" alt="flex col reverse" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Use case:</strong> Chat messages, timelines, or when newer content should appear at the bottom.</p>
<p>Now you know a bit about managing flex-directions using tailwind utility classes. You can mange the stack depending on your needs.</p>
<h3 id="heading-responsive-control">Responsive Control</h3>
<p>Tailwind also allows you to change flex direction at different breakpoints so you’ll get a clean layout across different devices.</p>
<pre><code class="language-html">&lt;div class="flex flex-col md:flex-row"&gt;
	.....
&lt;/div&gt;
</code></pre>
<p>This stacks items vertically on small screens and switches to a horizontal layout on medium screens and above.</p>
<h2 id="heading-fine-tuning-flexbox-layout">Fine-Tuning Flexbox Layout</h2>
<p>Once a container is set to use Flexbox, the real power comes from controlling how flex items behave inside it. This is where properties like wrap, order, and gap become essential. These features determine how items flow, how they're visually arranged, and how much space exists between them.</p>
<p>In real-world layouts such as card grids, navigation menus, and dashboards, elements rarely fit perfectly in a single row or follow a fixed order across all screen sizes. Flexbox provides solutions to these challenges, and Tailwind CSS exposes them through simple, intuitive utility classes.</p>
<ul>
<li><p><strong>Wrap</strong> helps manage what happens when items exceed the available space</p>
</li>
<li><p><strong>Order</strong> allows you to rearrange elements visually without changing the HTML structure</p>
</li>
<li><p><strong>Gap</strong> controls spacing between items in a clean and predictable way</p>
</li>
</ul>
<p>Let’s dive into the depths of these fine-tuning flexbox properties.</p>
<h3 id="heading-flex-wrap"><a href="https://tailwindcss.com/docs/flex-wrap">flex-wrap</a></h3>
<p>By default, Flexbox tries to fit all items into one line. If there isn’t enough space, items will shrink to squeeze in. <code>flex-wrap</code> allows flex-items to move onto the next line instead of shrinking.</p>
<pre><code class="language-xml">&lt;div class="flex flex-wrap"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>flex-nowrap</code>: (default) All items stay on one line.</p>
</li>
<li><p><code>flex-wrap</code>: Items wrap onto multiple lines.</p>
</li>
<li><p><code>flex-wrap-reverse</code>: Items wrap, but in reverse order.</p>
</li>
</ul>
<h3 id="heading-flex-order">flex-order</h3>
<p><a href="https://tailwindcss.com/docs/order">flex-order</a> controls the visual order of the stack/flex-items without changing the HTML structure. Each item has an order value. Items with lower order values appear first.</p>
<pre><code class="language-xml">&lt;div class="flex"&gt;
	&lt;div class="order-3 ..."&gt;01&lt;div&gt;
	&lt;div class="order-1 ..."&gt;02&lt;div&gt;
	&lt;div class="order-2 ..."&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357768674/b70b52ca-712e-409a-a0af-f73be8b2c649.png" alt="default order custom order" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Utility classes:</strong></p>
<ul>
<li><p><code>order-1</code> to <code>order-12</code>: Sets order value.</p>
</li>
<li><p><code>order-first</code>: Moves item to the start.</p>
</li>
<li><p><code>order-last</code>: Moves item to the end.</p>
</li>
<li><p><code>order-none</code>: Default order (0).</p>
</li>
</ul>
<h3 id="heading-gap">gap</h3>
<p><a href="https://tailwindcss.com/docs/gap">gap</a> controls the space between flex items, both rows and columns, without using margins. You can also apply for axis, which will help in giving space in both horizontal and vertical directions.</p>
<p>Here's an example of using it with a horizontal layout:</p>
<pre><code class="language-xml">&lt;div class="flex gap-8"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357860338/520e4c08-e334-4bee-9003-d6b22e857a18.png" alt="gap" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>And here's an example showing a vertical layout:</p>
<pre><code class="language-xml">&lt;div class="flex flex-col gap-y-5"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770357897235/488b63a8-b520-4b3e-b83b-1b18a316f23d.png" alt="gap y 5" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>gap-&lt;number&gt;</code>: Applies space (x-axis by default) between items according to the number, as shown in the example.</p>
</li>
<li><p><code>gap-[&lt;custom-property&gt;]</code>: You can apply a custom gap inside square brackets, such as <code>gap-[10px]</code>.</p>
</li>
<li><p><code>gap-x-&lt;number&gt;</code>: Provides horizontal spacing only.</p>
</li>
<li><p><code>gap-y-&lt;number&gt;</code>: Provides vertical spacing only.</p>
</li>
</ul>
<h3 id="heading-responsive-design">Responsive Design</h3>
<p>You can prefix&nbsp;the <code>gap</code>, <code>column-gap</code>,&nbsp;and&nbsp;<code>row-gap</code>&nbsp;utilities&nbsp;with a breakpoint variant, like&nbsp;<code>lg:</code>&nbsp;to only apply the utility at&nbsp;larger&nbsp;screen sizes and above. Here's an example:</p>
<pre><code class="language-xml">&lt;div class="flex gap-4 lg:gap-8 ..."&gt;
  &lt;!-- ... --&gt;
&lt;/div&gt;
</code></pre>
<h2 id="heading-how-to-justify-and-align-flex-items-in-tailwind">How to Justify and Align Flex Items in Tailwind</h2>
<p>If you're building interactive components like dropdowns, menus, or toolbars using Flexbox, alignment becomes even more important when handling keyboard navigation.</p>
<p>For example, when using arrow keys to navigate horizontally aligned items (<code>justify-between</code>, <code>justify-center</code>, and so on), proper spacing ensures a better user experience. You can explore how <a href="https://flyonui.com/docs/content/keyboard">Tailwind CSS keyboard</a> navigation works with <a href="https://flyonui.com/docs/content/keyboard/#arrow-keys">arrow keys</a> in FlyonUI.</p>
<p>FlyonUI provides accessible <a href="https://flyonui.com/docs/component/">Tailwind components</a> that integrate smoothly with Tailwind CSS, especially helpful when building flex-based navigation layouts.</p>
<p>Tailwind CSS offers a wide range of utility classes for aligning and justifying flex items, which can sometimes be confusing to differentiate. Below is a concise overview of these classes, along with practical examples.</p>
<h3 id="heading-justify-content">justify-content</h3>
<p><a href="https://tailwindcss.com/docs/justify-content">justify-content</a> is a flexbox property that controls how flex items are aligned along the main axis of a flex container. It decides how items are spaced inside a flex container. It is applied along with class <code>flex</code>.</p>
<p>Here's an example:</p>
<pre><code class="language-xml">&lt;div class="flex justify-start gap-2"&gt;
	&lt;div&gt;01&lt;div&gt;
	&lt;div&gt;02&lt;div&gt;
	&lt;div&gt;03&lt;div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770358388754/3fc9155b-067b-4ebd-9b75-037da1b34a00.png" alt="Justify Content" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>justify-start</code>: Aligns items at the start of the container.</p>
</li>
<li><p><code>justify-center</code>: Centers items along the main axis.</p>
</li>
<li><p><code>justify-end</code>: Aligns items at the end of the container.</p>
</li>
<li><p><code>justify-between</code>: Adds space between items, pushing first and last items to the edges.</p>
</li>
<li><p><code>justify-around</code>: Adds equal space around each item.</p>
</li>
<li><p><code>justify-evenly</code>: Distributes items with equal spacing everywhere, including edges.</p>
</li>
</ul>
<h3 id="heading-align-items">Align Items</h3>
<p><a href="https://tailwindcss.com/docs/align-items">align-items</a> is a flexbox property that controls how flex items are aligned along the <strong>cross-axis</strong> of a flex container.</p>
<p>In a row-based flex container (<code>flex-row</code>, which is the default direction), the cross axis is <strong>vertical</strong>. That means <code>align-items</code> controls vertical alignment.</p>
<p>In a column-based container (<code>flex-col</code>), the cross axis becomes <strong>horizontal</strong>, so <code>align-items</code> controls horizontal alignment instead.</p>
<p>This property is applied alongside the <code>flex</code> class and is commonly used to align items consistently inside navigation bars, toolbars, cards, and forms.</p>
<pre><code class="language-xml">&lt;div class="flex items-start gap-2"&gt;
	&lt;div&gt;01&lt;/div&gt;
	&lt;div&gt;02&lt;/div&gt;
	&lt;div&gt;03&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1770358590807/6440854e-822a-449d-ab22-fc417916bc45.png" alt="align text flexbox" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p><strong>Utility classes</strong>:</p>
<ul>
<li><p><code>items-start</code>: Aligns items to the start of the cross-axis (top in a row).</p>
</li>
<li><p><code>items-center</code>: Centers items vertically along the cross-axis.</p>
</li>
<li><p><code>items-end</code>: Aligns items to the end of the cross axis (bottom in a row).</p>
</li>
<li><p><code>items-baseline</code>: Aligns items based on their text baseline.</p>
</li>
<li><p><code>items-stretch</code>: Stretches items to fill the container (default behavior).</p>
</li>
</ul>
<h2 id="heading-practice-flexbox-with-interactive-games">Practice Flexbox with Interactive Games</h2>
<p>Reading documentation is important, but Flexbox really <em>clicks</em> when you practice it visually. One of the best ways to build strong Flexbox intuition is through interactive games that let you experiment with alignment, spacing, and direction in real time.</p>
<p>Here are two excellent games that will strengthen your Flexbox fundamentals and make Tailwind’s flex utilities feel second nature:</p>
<h3 id="heading-flexbox-froggy">Flexbox Froggy</h3>
<p>🔗 <a href="https://flexboxfroggy.com/">https://flexboxfroggy.com/</a></p>
<p>Flexbox Froggy is a fun and beginner-friendly game where you help frogs reach their lily pads using Flexbox properties. Each level introduces a new concept, like <code>justify-content</code>, <code>align-items</code>, <code>flex-direction</code>, and <code>flex-wrap</code>.</p>
<p><strong>Why it’s great:</strong></p>
<ul>
<li><p>Perfect for beginners</p>
</li>
<li><p>Visual feedback makes concepts easy to grasp</p>
</li>
<li><p>Covers core Flexbox properties step by step</p>
</li>
</ul>
<p>If you’re new to Flexbox, this is one of the best places to start.</p>
<h3 id="heading-flexbox-adventure-coding-fantasy">Flexbox Adventure (Coding Fantasy)</h3>
<p>🔗 <a href="https://codingfantasy.com/games/flexboxadventure">https://codingfantasy.com/games/flexboxadventure</a></p>
<p>Flexbox Adventure turns Flexbox learning into a role-playing game where you move your character by writing Flexbox rules. It focuses more on real-world layout thinking and helps reinforce how different properties work together.</p>
<p><strong>Why it’s great:</strong></p>
<ul>
<li><p>More challenging than Flexbox Froggy</p>
</li>
<li><p>Helps solidify intermediate concepts</p>
</li>
<li><p>Encourages problem-solving with Flexbox logic</p>
</li>
</ul>
<p>This is a great follow-up once you’re comfortable with the basics.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Flexbox is a core part of modern CSS layouts, and Tailwind CSS makes it even more powerful by turning Flexbox properties into simple, readable utility classes. By understanding utilities for direction, sizing, wrapping, spacing, ordering, and alignment, you can build responsive and flexible layouts without writing custom CSS.</p>
<p>And by understanding how properties like <code>flex</code>, <code>grow</code>, <code>shrink</code>, <code>basis</code>, <code>justify-*</code>, <code>items-*</code>, <code>gap</code>, when responsive variants work together, you can build layouts that are not only flexible and responsive but also maintainable and scalable.</p>
<p>Instead of wrestling with custom CSS, Tailwind allows you to express layout intent directly in your markup, keeping your workflow fast and predictable.</p>
<p>With these Flexbox fundamentals in your toolkit, you’re well-equipped to design clean, responsive interfaces using Tailwind CSS with confidence. 🚀</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Center Any Element in CSS: 7 Methods That Always Work ]]>
                </title>
                <description>
                    <![CDATA[ Centering elements in CSS often seems straightforward at first, but it quickly becomes confusing once you start building real layouts. A property like text-align: center; works perfectly for text, yet ]]>
                </description>
                <link>https://www.freecodecamp.org/news/center-any-element-in-css/</link>
                <guid isPermaLink="false">69ab2d340bca1a397644f893</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Fanny Nyayic ]]>
                </dc:creator>
                <pubDate>Fri, 06 Mar 2026 19:38:28 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5fc16e412cae9c5b190b6cdd/0dcc3b91-56fd-4102-8d3c-2490ea67b7e8.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Centering elements in CSS often seems straightforward at first, but it quickly becomes confusing once you start building real layouts. A property like <code>text-align: center;</code> works perfectly for text, yet it fails when you try to center an image or a block element.</p>
<p>Then you experiment with <code>margin: auto;</code>, which centers a <code>div</code> horizontally but doesn’t help with vertical alignment. Before long, you find yourself searching through solutions involving Flexbox, Grid, transforms, and other techniques that appear complicated and inconsistent.</p>
<p>The reality is that CSS does not provide a single universal property that can center everything. Instead, each layout scenario requires the right method, and understanding when to use each technique is the key to mastering CSS centering.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a href="#heading-first-understand-the-two-types-of-centering">First: Understand the Two Types of Centering</a></p>
</li>
<li><p><a href="#heading-method-1-center-inline-content-text-inline-elements">Method 1: Center Inline Content (text, inline elements)</a></p>
</li>
<li><p><a href="#heading-method-2-center-a-block-horizontally">Method 2: Center a Block Horizontally</a></p>
</li>
<li><p><a href="#heading-method-3-perfect-center-horizontal-vertical-with-flexbox">Method 3: Perfect Center (Horizontal + Vertical) with Flexbox</a></p>
</li>
<li><p><a href="#heading-method-4-center-using-css-grid-the-easiest-method-ever">Method 4: Center Using CSS Grid (The Easiest Method Ever)</a></p>
</li>
<li><p><a href="#heading-method-5-center-with-absolute-position-transform">Method 5: Center with Absolute Position + Transform</a></p>
</li>
<li><p><a href="#heading-method-6-vertical-center-single-line-text">Method 6: Vertical Center Single Line Text</a></p>
</li>
<li><p><a href="#heading-method-7-the-table-cell-method-old-but-useful">Method 7: The Table-Cell Method (Old but Useful)</a></p>
</li>
<li><p><a href="#heading-quick-decision-guide">Quick Decision Guide</a></p>
</li>
<li><p><a href="#heading-common-beginner-problems-and-fixes">Common Beginner Problems (And Fixes)</a></p>
</li>
<li><p><a href="#heading-pro-tips-youll-use-forever">Pro Tips You’ll Use Forever</a></p>
</li>
<li><p><a href="#heading-summary">Summary</a></p>
</li>
<li><p><a href="#heading-the-7-methods-you-should-memorize">The 7 Methods You Should Memorize</a></p>
</li>
</ul>
<h2 id="heading-first-understand-the-two-types-of-centering"><strong>First: Understand the Two Types of Centering</strong></h2>
<p>Before diving into centering techniques, it’s important to understand the two types of centering in CSS, because different methods work along different axes. CSS layouts operate on two axes: Knowing which axis you want to center along helps you choose the right approach.</p>
<p>There are two axes in CSS layout:</p>
<table style="width:709px"><colgroup><col style="width:385px"><col style="width:324px"></colgroup><tbody><tr><td><p><strong>Axis</strong></p></td><td><p><strong>Direction</strong></p></td></tr><tr><td><p>Horizontal</p></td><td><p>Left to Right</p></td></tr><tr><td><p>Vertical</p></td><td><p>Top to Bottom</p></td></tr></tbody></table>

<p>When someone says <em>“center this element”</em>, they usually mean one of four things:</p>
<ul>
<li><p>Center text inside a container</p>
</li>
<li><p>Center a block horizontally</p>
</li>
<li><p>Center vertically</p>
</li>
<li><p>Center both horizontally and vertically</p>
</li>
</ul>
<p>Each requires a different solution.</p>
<h2 id="heading-method-1-center-inline-content-text-inline-elements"><strong>Method 1: Center Inline Content (text, inline elements)</strong></h2>
<p>This method centers inline content such as text, links, inline images, and sometimes buttons, using the <code>text-align: center;</code> property. This is the simplest centering method in CSS, but it is often misunderstood because it only affects the content inside a block container, not the container itself.</p>
<h3 id="heading-example"><strong>Example</strong></h3>
<pre><code class="language-html">&lt;div class="box"&gt;
&nbsp;&nbsp;&lt;h2&gt;Hello World&lt;/h2&gt;
&nbsp;&nbsp;&lt;p&gt;This text is centered.&lt;/p&gt;
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.box {
&nbsp;&nbsp;text-align: center;
&nbsp;&nbsp;border: 2px solid #444;
&nbsp;&nbsp;padding: 20px;
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/f9c2bb33-f6aa-4b12-b5cc-2d3cc9d76032.png" alt="f9c2bb33-f6aa-4b12-b5cc-2d3cc9d76032" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h3 id="heading-why-it-works"><strong>Why It Works</strong></h3>
<p>When you apply <code>text-align: center;</code> to a parent element, the browser horizontally aligns all inline and inline-block children within that container. This makes it perfect for centering headings, paragraphs, navigation links, or small inline elements, but it won’t work for block-level elements like divs unless their display is changed to inline-block.</p>
<p>So this will NOT work:</p>
<pre><code class="language-css">.box {
&nbsp;&nbsp;width: 300px;
&nbsp;&nbsp;text-align: center; /* does NOT center the box */
}
</code></pre>
<h3 id="heading-real-world-use-cases"><strong>Real-world use cases</strong></h3>
<ul>
<li><p>Center headings</p>
</li>
<li><p>Center button labels</p>
</li>
<li><p>Navigation menus</p>
</li>
<li><p>Card content alignment</p>
</li>
</ul>
<h3 id="heading-beginner-mistake"><strong>Beginner Mistake</strong></h3>
<p>Most people try to center a <code>&lt;div&gt;</code> with <code>text-align: center;</code>. This won’t move the <code>div</code>, only its contents.</p>
<h2 id="heading-method-2-center-a-block-horizontally"><strong>Method 2: Center a Block Horizontally</strong></h2>
<p>This method centers a block element horizontally using <code>margin: 0 auto;</code>, which is one of the oldest and most reliable CSS techniques. It works by automatically distributing the available horizontal space equally on the left and right sides of the element. When you set the left and right margins to auto, the browser calculates the remaining space in the container and splits it evenly, pushing the element into the center.</p>
<p>Works when:</p>
<ul>
<li><p>Element has a width</p>
</li>
<li><p>Element is block-level</p>
</li>
</ul>
<h3 id="heading-example-center-a-card"><strong>Example, Center a Card</strong></h3>
<pre><code class="language-html">&lt;div class="card"&gt;
&nbsp;&nbsp;I am centered!
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.card {
&nbsp;&nbsp;width: 300px;
&nbsp;&nbsp;margin: 0 auto;
&nbsp;&nbsp;padding: 20px;
&nbsp;&nbsp;background: #eee;
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/1f1e1df4-7e33-4f54-a9f7-c688c5432782.png" alt="1f1e1df4-7e33-4f54-a9f7-c688c5432782" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h3 id="heading-why-it-works"><strong>Why It Works</strong></h3>
<p>When you set the elements' margins to auto, the browser calculates the remaining horizontal space in the container after accounting for the element’s width. It then distributes this extra space equally between the left and right margins, which pushes the element into the center. This happens automatically, making <code>margin: 0 auto;</code> a simple and reliable way to horizontally center block elements with a fixed width.</p>
<pre><code class="language-xml">|----auto----|---element---|----auto----|
</code></pre>
<p>Browser calculates: left margin = right margin. So the element sits in the middle.</p>
<h3 id="heading-important-rule"><strong>Important Rule</strong></h3>
<p>If width is not defined, it won't work:</p>
<pre><code class="language-css">.card {
&nbsp;&nbsp;margin: auto; /* won't center , takes full width */
}
</code></pre>
<p>Because block elements default to <code>width: 100%;</code>.</p>
<h3 id="heading-real-world-use-cases"><strong>Real-world use cases</strong></h3>
<ul>
<li><p>Center website layout container</p>
</li>
<li><p>Center forms</p>
</li>
<li><p>Center blog content area</p>
</li>
</ul>
<h2 id="heading-method-3-perfect-center-horizontal-vertical-with-flexbox"><strong>Method 3: Perfect Center (Horizontal + Vertical) with Flexbox</strong></h2>
<p>This method uses Flexbox to center an element both horizontally and vertically, making it one of the most reliable modern CSS solutions. When you set a container to <code>display: flex;</code>, you activate the Flexbox layout system, which gives you powerful alignment controls. The property <code>justify-content: center;</code> centers the content along the main axis (usually horizontal), while <code>align-items: center;</code> centers it along the cross axis (usually vertical).</p>
<h3 id="heading-example-center-login-box"><strong>Example, Center Login Box</strong></h3>
<pre><code class="language-html">&lt;div class="page"&gt;
&nbsp;&nbsp;&lt;div class="login"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;Login Form
&nbsp;&nbsp;&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">
.page {
&nbsp;&nbsp;height: 100vh;
&nbsp;&nbsp;display: flex;
&nbsp;&nbsp;justify-content: center;
&nbsp;&nbsp;align-items: center;
}

.login {
&nbsp;&nbsp;padding: 40px;
&nbsp;&nbsp;background: white;
&nbsp;&nbsp;border: 2px solid #333;
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/e7c4abc2-1d23-4933-9b3a-dad52326e924.png" alt="e7c4abc2-1d23-4933-9b3a-dad52326e924" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h3 id="heading-why-it-works"><strong>Why It Works</strong></h3>
<p>Flexbox treats the container and its children as a flexible layout system, automatically distributing space along the main and cross axes. This allows any element, regardless of its size, to sit perfectly in the middle of the container, making it ideal for centering modals, hero sections, and other dynamic content.</p>
<table style="width:733px"><colgroup><col style="width:536px"><col style="width:197px"></colgroup><tbody><tr><td><p><strong>Property</strong></p></td><td><p><strong>Controls</strong></p></td></tr><tr><td><p>justify-content</p></td><td><p>horizontal</p></td></tr><tr><td><p>align-items</p></td><td><p>vertical</p></td></tr></tbody></table>

<h3 id="heading-this-works-regardless-of"><strong>This Works Regardless Of:</strong></h3>
<ul>
<li><p>Unknown height</p>
</li>
<li><p>Unknown width</p>
</li>
<li><p>Responsive layouts</p>
</li>
<li><p>Dynamic content</p>
</li>
</ul>
<p>That’s why it’s widely used today.</p>
<h3 id="heading-real-world-use-cases"><strong>Real-world use cases</strong></h3>
<p>Developers commonly use Flexbox centering to place important interface elements directly in the middle of the screen. For example, it helps center modal dialogs, loading spinners, hero section content, and other full-screen UI components. Hence, they remain visually balanced and easy for users to notice, regardless of screen size.</p>
<h2 id="heading-method-4-center-using-css-grid-the-easiest-method-ever"><strong>Method 4: Center Using CSS Grid (The Easiest Method Ever)</strong></h2>
<p>CSS Grid offers one of the simplest ways to center elements both horizontally and vertically. By setting a container to <code>display: grid;</code> and applying <code>place-items: center;</code>, you can position any child element perfectly in the middle with just a few lines of code. This method works because Grid provides built-in alignment controls that automatically handle positioning along both axes.</p>
<h3 id="heading-example"><strong>Example</strong></h3>
<pre><code class="language-html">&lt;div class="wrapper"&gt;
&nbsp;&nbsp;&lt;div class="box"&gt;Centered!&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">
.wrapper {
&nbsp;&nbsp;height: 100vh;
&nbsp;&nbsp;display: grid;
&nbsp;&nbsp;place-items: center;
}
.box {
  width: 200px;
  padding: 30px;
  text-align: center;
  background: white;
  border: 2px solid #333;
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/fb959081-1adb-467b-bf7d-754ec2777566.png" alt="fb959081-1adb-467b-bf7d-754ec2777566" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>In this example, the <code>.wrapper</code> acts as the grid container, and the <code>.box</code> element becomes a grid item. The property <code>place-items: center;</code> automatically aligns the box in the middle of the container, both horizontally and vertically.</p>
<p><code>100vh</code> means 100% of the viewport height, which is the full height of the visible browser window. When you set <code>height: 100vh;</code> on a container, it expands to fill the entire screen from top to bottom.</p>
<h3 id="heading-why-it-works">Why It Works</h3>
<p>The property <code>place-items: center</code> is actually shorthand for two grid alignment properties:</p>
<pre><code class="language-css">align-items: center;
justify-items: center;
</code></pre>
<ul>
<li><p><code>align-items</code> controls vertical alignment inside the grid.</p>
</li>
<li><p><code>justify-items</code> controls horizontal alignment.</p>
</li>
</ul>
<p>By combining both in one line, Grid centers elements in both directions automatically without needing additional layout rules.</p>
<h3 id="heading-when-to-prefer-grid-over-flexbox"><strong>When to Prefer Grid Over Flexbox</strong></h3>
<p>CSS Grid is ideal when you only need simple centering and don’t require complex layout control. It keeps your code short and easy to read.</p>
<p><strong>Use Grid when:</strong></p>
<ul>
<li><p>You only need to center a single element</p>
</li>
<li><p>You are not building complex layouts</p>
</li>
<li><p>You want the simplest and cleanest code</p>
</li>
</ul>
<p><strong>Use Flexbox when:</strong></p>
<ul>
<li><p>You are aligning multiple items</p>
</li>
<li><p>Layout direction matters (row vs column)</p>
</li>
<li><p>You need spacing control between elements</p>
</li>
</ul>
<h2 id="heading-method-5-center-with-absolute-position-transform"><strong>Method 5: Center with Absolute Position + Transform</strong></h2>
<p>This centers an element using absolute positioning combined with CSS transforms, and it works even when you are not using Flexbox or Grid. In this approach, you position the element with <code>position: absolute;</code> and move it to the middle of its parent using <code>top: 50%;</code> and <code>left: 50%;</code>.</p>
<h3 id="heading-example-center-popup"><strong>Example, Center Popup</strong></h3>
<pre><code class="language-html">&lt;div class="container"&gt;
&nbsp;&nbsp;&lt;div class="popup"&gt;I'm centered&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.container {
&nbsp;&nbsp;position: relative;
&nbsp;&nbsp;height: 400px;
}

.popup {
&nbsp;&nbsp;position: absolute;
&nbsp;&nbsp;top: 50%;
&nbsp;&nbsp;left: 50%;
&nbsp;&nbsp;transform: translate(-50%, -50%);
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/bc20cc8d-090c-45cf-a240-8792c6963784.png" alt="bc20cc8d-090c-45cf-a240-8792c6963784" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h3 id="heading-why-it-works"><strong>Why It Works</strong></h3>
<ol>
<li><p><code>top: 50%</code> moves the top edge to the middle</p>
</li>
<li><p><code>left: 50%</code> moves the left edge to the middle</p>
</li>
<li><p><code>translate(-50%, -50%)</code> shifts the element back by half its size</p>
</li>
</ol>
<p>So the center becomes the element’s midpoint, not the corner.</p>
<h3 id="heading-explanation"><strong>Explanation</strong></h3>
<p><strong>Without transform:</strong> The element corner sits at the center, which means this places the top-left corner of the element at the center point.</p>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/f579c42a-074f-4bda-8fab-5c8163ff8fac.png" alt="f579c42a-074f-4bda-8fab-5c8163ff8fac" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<p>To fix that, you apply <code>transform: translate(-50%, -50%);</code>, which shifts the element back by half of its own width and height. This adjustment ensures the actual center of the element aligns with the center of the container. Developers often use this technique for overlays, modals, tooltips, and floating UI components.</p>
<h3 id="heading-real-world-use-cases"><strong>Real-world use cases</strong></h3>
<ul>
<li><p>Modals</p>
</li>
<li><p>Tooltips</p>
</li>
<li><p>Floating labels</p>
</li>
<li><p>Overlays</p>
</li>
</ul>
<h2 id="heading-method-6-vertical-center-single-line-text"><strong>Method 6: Vertical Center Single Line Text</strong></h2>
<p>This method vertically centers single-line text inside a container by using the <code>line-height</code> property. When you set the <code>line-height</code> to the same value as the container’s height, the browser places the text in the vertical middle of that space because the line box expands to fill the container evenly.</p>
<h3 id="heading-example-center-text-in-button"><strong>Example, Center Text in Button</strong></h3>
<pre><code class="language-html">&lt;button class="btn"&gt;Click Me&lt;/button&gt;
</code></pre>
<pre><code class="language-css">.btn {
&nbsp;&nbsp;height: 60px;
&nbsp;&nbsp;line-height: 60px;
&nbsp;&nbsp;text-align: center;
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/be456849-c4b8-49aa-a330-fe448b9a5ee6.png" alt="be456849-c4b8-49aa-a330-fe448b9a5ee6" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h3 id="heading-why-it-works"><strong>Why It Works</strong></h3>
<p>This technique works best for elements with a fixed height, such as buttons, badges, or navigation items. However, it only works reliably when the text stays on one line, because multiple lines will break the vertical alignment.</p>
<h3 id="heading-limitations"><strong>Limitations</strong></h3>
<p>The main limitation of using <code>line-height</code> to vertically center text is that it only works for single-line text. If the text wraps onto multiple lines, the line-height no longer matches the container height for each line, causing the vertical centering to break.</p>
<p>This makes the method unsuitable for paragraphs, headings, or any content that can expand beyond one line, so it’s best reserved for buttons, labels, or other fixed-height, single-line elements.</p>
<h2 id="heading-method-7-the-table-cell-method-old-but-useful"><strong>Method 7: The Table-Cell Method (Old but Useful)</strong></h2>
<p>This method uses the table-cell technique to center content vertically and horizontally, a reliable approach for older CSS layouts and email templates. By setting a container to <code>display: table;</code> and its child element to <code>display: table-cell;</code> with <code>vertical-align: middle;</code> and <code>text-align: center;</code>, The browser treats the child like a table cell and automatically centers its content.</p>
<h3 id="heading-example"><strong>Example</strong></h3>
<pre><code class="language-html">&lt;div class="outer"&gt;
&nbsp;&nbsp;&lt;div class="inner"&gt;Centered&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<pre><code class="language-css">.outer {
&nbsp;&nbsp;display: table;
&nbsp;&nbsp;width: 100%;
&nbsp;&nbsp;height: 300px;
}

.inner {
&nbsp;&nbsp;display: table-cell;
&nbsp;&nbsp;vertical-align: middle;
&nbsp;&nbsp;text-align: center;
}
</code></pre>
<h3 id="heading-output">Output</h3>
<img src="https://cdn.hashnode.com/uploads/covers/5db98fb03e191a79566dbb68/e0960bcf-bd1c-43c0-9d1b-afa48530fd8d.png" alt="e0960bcf-bd1c-43c0-9d1b-afa48530fd8d" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h3 id="heading-how-it-works"><strong>How It Works</strong></h3>
<ul>
<li><p>The <code>.outer</code> container acts as a table.</p>
</li>
<li><p>The <code>.inner</code> element behaves like a table cell.</p>
</li>
<li><p>Table cells automatically respect vertical alignment rules.</p>
</li>
<li><p>Combining <code>vertical-align: middle;</code> and <code>text-align: center;</code> perfectly centers the content both vertically and horizontally.</p>
</li>
</ul>
<h3 id="heading-why-use-this-method">Why Use This Method</h3>
<ul>
<li><p>It works in <strong>older browsers</strong> that don’t fully support Flexbox or Grid.</p>
</li>
<li><p>It’s especially useful in <strong>email templates</strong> or <strong>legacy layouts</strong>.</p>
</li>
<li><p>No knowledge of height calculation or transforms is required.</p>
</li>
</ul>
<h2 id="heading-quick-decision-guide"><strong>Quick Decision Guide</strong></h2>
<table style="width:754px"><colgroup><col style="width:491px"><col style="width:263px"></colgroup><tbody><tr><td><p><strong>Situation</strong></p></td><td><p><strong>Best Method</strong></p></td></tr><tr><td><p>Center text</p></td><td><p>text-align</p></td></tr><tr><td><p>Center block horizontally</p></td><td><p>margin auto</p></td></tr><tr><td><p>Center anything modern</p></td><td><p>flexbox</p></td></tr><tr><td><p>Simplest full center</p></td><td><p>grid</p></td></tr><tr><td><p>Overlay/modal</p></td><td><p>absolute + transform</p></td></tr><tr><td><p>Single-line text vertical</p></td><td><p>line-height</p></td></tr><tr><td><p>Legacy/email support</p></td><td><p>table-cell</p></td></tr></tbody></table>

<h2 id="heading-common-beginner-problems-and-fixes"><strong>Common Beginner Problems (And Fixes)</strong></h2>
<h3 id="heading-problem-1-margin-auto-not-working"><strong>Problem 1: “margin auto not working.”</strong></h3>
<p>You forgot the width.</p>
<pre><code class="language-css">width: 300px;
margin: auto;
</code></pre>
<h3 id="heading-problem-2-align-items-center-not-working"><strong>Problem 2: “align-items center not working.”</strong></h3>
<p>Parent needs height.</p>
<pre><code class="language-css">height: 100vh;
</code></pre>
<h3 id="heading-problem-3-absolute-centering-weird-position"><strong>Problem 3: “absolute centering weird position.”</strong></h3>
<p>Parent missing positioning.</p>
<pre><code class="language-css">parent { position: relative; }
</code></pre>
<h3 id="heading-problem-4-flexbox-vertical-centering-fails"><strong>Problem 4: Flexbox vertical centering fails</strong></h3>
<p>Check direction:</p>
<pre><code class="language-css">flex-direction: column;
</code></pre>
<p>Now vertical/horizontal axes swap!</p>
<h2 id="heading-pro-tips-youll-use-forever"><strong>Pro Tips You’ll Use Forever</strong></h2>
<blockquote>
<p>1. Flexbox = alignment tool</p>
<p>2. Grid = placement tool</p>
<p>3. Margin auto = layout tool</p>
</blockquote>
<p>Different tools, different jobs.</p>
<h3 id="heading-remember-this-rule"><strong>Remember This Rule</strong></h3>
<ul>
<li><p>If you are centering one thing, use Grid</p>
</li>
<li><p>If centering many things, use Flexbox</p>
</li>
</ul>
<h2 id="heading-summary"><strong>Summary</strong></h2>
<p>CSS centering often feels difficult because beginners expect a single magic property that works in every situation, but no such property exists. Instead, CSS provides multiple layout systems, each designed to solve specific alignment problems.</p>
<p>These include inline alignment for text and inline elements, flow layout for standard block elements, Flexbox for flexible row or column arrangements, Grid for two-dimensional layouts, and positioned layouts for absolute or fixed elements. Once you understand which system applies to your scenario, centering becomes predictable and much easier to implement.</p>
<h2 id="heading-the-7-methods-you-should-memorize"><strong>The 7 Methods You Should Memorize</strong></h2>
<ol>
<li><p><code>text-align: center</code></p>
</li>
<li><p><code>margin: 0 auto</code></p>
</li>
<li><p>Flexbox centering</p>
</li>
<li><p>Grid <code>place-items: center</code></p>
</li>
<li><p>Absolute + transform</p>
</li>
<li><p>Line-height trick</p>
</li>
<li><p>Table-cell fallback</p>
</li>
</ol>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn CSS Flexbox for Beginners [Free 2-hour course] ]]>
                </title>
                <description>
                    <![CDATA[ Flexbox is a powerful CSS feature that lets you build user interfaces that fit any screen size. freeCodeCamp just published a Flexbox for beginners course where you'll learn the concepts and code syntax by building your own website navigation bar. If... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-css-flexbox-for-beginners-free-2-hour-course/</link>
                <guid isPermaLink="false">6925eef4915ee815a9b000df</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ course ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Quincy Larson ]]>
                </dc:creator>
                <pubDate>Tue, 25 Nov 2025 18:01:24 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1764093380745/42ec6fe5-355a-4a0d-acb1-8e63e2b1c240.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Flexbox is a powerful CSS feature that lets you build user interfaces that fit any screen size. freeCodeCamp just published a Flexbox for beginners course where you'll learn the concepts and code syntax by building your own website navigation bar.</p>
<p>If you’ve ever struggled to center something with CSS or tried to make columns line up nicely, Flexbox simplifies this dramatically. With just a few properties, you can build modern layouts that “flex” to different screen sizes, without needing to write a bunch of custom media queries.</p>
<p>Developer and teacher Indra (CodeWithIndra) will walk you through every Flexbox property step by step. You’ll learn how to align items along the main and cross axis, reorder elements without changing the HTML, control how items grow and shrink, and finally understand what flex-grow, flex-shrink, and flex-basis are really doing. He also shows real examples from sites like GitHub and DataDog, then demonstrates how to recreate pieces of their layout.</p>
<p>The course ends with two small projects: centering an element vertically and horizontally (the thing everyone Googles at some point) and building a clean navigation bar using only Flexbox.</p>
<p>If you want to improve your front end development skills, this course is a good way to invest a couple hours of your weekend. [2 hour YouTube course]:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/nbsz6muQRT4" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn CSS Flexbox in Spanish – Course for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ With CSS Flexbox, you can easily create responsive websites that adapt to different screen sizes and devices. It's an essential skill for any modern web developer. We just published a course on the freeCodeCamp.org Spanish YouTube channel that will t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-css-flexbox-in-spanish-course-for-beginners/</link>
                <guid isPermaLink="false">66b1f840125aeccef6f65c33</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Español ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Estefania Cassingena Navone ]]>
                </dc:creator>
                <pubDate>Tue, 20 Feb 2024 15:50:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/Thumbnail-1-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>With CSS Flexbox, you can easily create responsive websites that adapt to different screen sizes and devices. It's an essential skill for any modern web developer.</p>
<p>We just published a course on the <a target="_blank" href="https://www.youtube.com/freecodecampespanol">freeCodeCamp.org Spanish YouTube channel</a> that will teach you Flexbox from the fundamentals. By the end of the course, you will be able to design and implement responsive layouts.</p>
<p>If you have Spanish-speaking friends, you are welcome to share the <strong><a target="_blank" href="https://www.freecodecamp.org/espanol/news/aprende-css-flexbox-desde-cero-curso-paso-a-paso">Spanish version of this article</a></strong> with them.</p>
<p>This course was created by Leosbel Poll Sotomayor. Leosbel is a software engineer with more than 10 years of experience. He started creating more than 20 years ago in Cuba, and is now living in Canada thanks to his programming skills. He created this course for the freeCodeCamp community.</p>
<p>Are you ready? Let's see a quick overview of Flexbox and what you will learn during the course.</p>
<h2 id="heading-what-is-css-flexbox"><strong>What is</strong> CSS <strong>Flexbox</strong>?<em>**</em></h2>
<p>CSS Flexbox stands for CSS Flexible Box Layout. It's a layout model that allows responsive elements to be rearranged within a container based on CSS properties that define how the children should "move" to fit the size of their container.</p>
<p>With Flexbox, you can align, distribute, and space elements using simple properties, so you can avoid complex computations in your CSS.</p>
<p>During the course, you will learn how to use these properties:</p>
<ul>
<li><code>**flex-direction**</code></li>
<li><code>**justify-content**</code></li>
<li><code>**flex-wrap**</code></li>
<li><code>**align-items**</code></li>
<li><code>**align-content**</code></li>
<li><code>**flex-grow**</code></li>
<li><code>**flex-basis**</code></li>
<li><code>**flex-shrink**</code></li>
</ul>
<p>And more! You will also learn how to combine them with media queries to create even more powerful responsive layouts.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/frame-3.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flexbox layout. Wrapping elements automatically.</em></p>
<h3 id="heading-career-opportunities"><strong>Career Opportunities</strong></h3>
<p>If your goal is to have a career in the field of web development, Flexbox will be super helpful for you. These skills are in high demand and widely sought by employers.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/frame-4.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flexbox layout. Classic design with a navigation bar, sidebar, main area, and footer.</em></p>
<h2 id="heading-flexbox-course-in-spanish"><strong>Flexbox </strong>Course in Spanish<em>**</em></h2>
<p>Awesome. Now that you know why Flexbox is so important, let's check out the topics that you will learn during the course:</p>
<ul>
<li>Introduction</li>
<li>What is Flexbox?</li>
<li>Importance of Flexbox</li>
<li>Flexbox Fundamentals</li>
<li>Tools that you will use during the course</li>
<li>How to set up your development environment</li>
<li>Properties related to containers</li>
<li>Loss of data in CSS</li>
<li>Properties related to children</li>
<li>Use case: Navigation Bar</li>
<li>Use case: Classic Design</li>
<li>Flexbox vs. Grid</li>
</ul>
<p>If you are ready to learn Flexbox, check out the course in Spanish on the <a target="_blank" href="https://www.youtube.com/freecodecampespanol">freeCodeCamp.org Spanish YouTube channel</a>:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/iwFEc6I8wSA" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<p>✍️ Course created by Leosbel Poll Sotomayor.</p>
<ul>
<li>YouTube: <a target="_blank" href="https://www.youtube.com/@_LeoDev">LeoDev</a></li>
<li>Twitter: <a target="_blank" href="https://twitter.com/_LeoDev">@_LeoDev</a></li>
<li>LinkedIn: <a target="_blank" href="https://www.linkedin.com/in/leosbel-poll-sotomayor/">Leosbel Poll Sotomayor</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Center Text Vertically with CSS ]]>
                </title>
                <description>
                    <![CDATA[ If you have some text inside a div, and nothing else, the div's height will match the text height. Suppose, though, you have some text and an image. Your text will be aligned at the bottom of the div, which is usually not what you want. In this artic... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-center-text-vertically-with-css/</link>
                <guid isPermaLink="false">66ba5659efd5e6f1088c7298</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joe Attardi ]]>
                </dc:creator>
                <pubDate>Mon, 23 Oct 2023 19:44:32 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/10/pexels-alexander-ermakov-12154194.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you have some text inside a <code>div</code>, and nothing else, the <code>div</code>'s height will match the text height. Suppose, though, you have some text and an image. Your text will be aligned at the bottom of the <code>div</code>, which is usually not what you want.</p>
<p>In this article, you'll learn a couple of ways to vertically center your text inside such a <code>div</code> or other element.</p>
<h2 id="heading-how-to-center-text-using-line-height">How to Center Text using Line Height</h2>
<p>This approach is limited, but can be useful if you have your element set to a fixed height using the <code>height</code> property.</p>
<p>The <code>line-height</code> property determines the height of the box that the browser renders text into. By default, this is set to a value slightly larger than 1 to provide comfortable spacing between lines of text.</p>
<p>If you set the element's <code>height</code> and <code>line-height</code> to the same value, the text will be vertically centered:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.my-element</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">3rem</span>;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">3rem</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/image-91.png" alt="Image" width="600" height="400" loading="lazy">
<em>Vertically centered text using line-height</em></p>
<p>There is an important caveat to this approach, though. This only works if your text can fit on one line.</p>
<p>If the text does wrap, you'll see the first line vertically centered. Because you set the <code>line-height</code> to be the same as the element's <code>height</code>, the wrapped line of text now overflows the element.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/image-94.png" alt="Image" width="600" height="400" loading="lazy">
<em>Wrapped text overflowing the container</em></p>
<p>If this sounds too rigid, read on. Next, you'll see how you can use Flexbox to vertically center your text, along with any other content inside the element.</p>
<h2 id="heading-how-to-center-text-using-flexbox">How to Center Text using Flexbox</h2>
<p>A better, more general-purpose solution, is to use a Flexbox layout with <code>align-items</code> set to <code>center</code>.</p>
<p>An element using Flexbox (the flex container) lays out elements (flex items) either in a row or column. A Flexbox layout has two imaginary lines running through it. The first is the <em>main</em> axis, along which items will be placed. For a <code>row</code> flexbox, the main axis is the horizontal axis.</p>
<p>The <em>cross</em> axis runs perpendicular to the main axis. You can use the cross axis to define the vertical alignment of elements inside the flex container.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/image-92.png" alt="Image" width="600" height="400" loading="lazy">
<em>The main and cross axis in a horizontal Flexbox layout</em></p>
<p>Here's the CSS you'll need to apply a Flexbox layout and vertically center the text:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.my-element</span> {
    <span class="hljs-comment">/* Use a flexbox layout */</span>
    <span class="hljs-attribute">display</span>: flex;

    <span class="hljs-comment">/* Make a horizontal flexbox (the default) */</span>
    <span class="hljs-attribute">flex-direction</span>: row;

    <span class="hljs-comment">/* The important part: vertically center the items */</span>
    <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<p>This creates a horizontal Flexbox layout (the <code>flex-direction: row</code> is not strictly required, as it's the default). The <code>align-items</code> property determines the alignment of items along the cross, or vertical, axis. There are a few different values you can use, but here you can use <code>center</code> to vertically center the text.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/image-96.png" alt="Image" width="600" height="400" loading="lazy">
<em>The text with align-items: center</em></p>
<p>This works nicely, and it even handles multiple lines of wrapped text. If you have other content inside the element, such as an image, everything will be aligned vertically.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/image-95.png" alt="Image" width="600" height="400" loading="lazy">
<em>The text is aligned vertically with other content</em></p>
<h2 id="heading-how-to-center-text-using-css-grid">How to Center Text Using CSS Grid</h2>
<p>You can also center your content vertically using CSS Grid. </p>
<p>For a single <code>div</code> containing the text to center, you can turn it into a grid layout with one row and one column.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.my-element</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<p>In a grid layout, the <code>align-items</code> property specifies the alignment of the content within the cell, along the column (vertical) axis. This vertically aligns your text within the <code>div</code> element.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/image-98.png" alt="Image" width="600" height="400" loading="lazy">
<em>Text vertically centered using a 1x1 grid layout</em></p>
<p>If the element containing your text is already part of a grid layout, you can either apply <code>align-items: center</code> to the entire grid, or if you just want to control the vertical alignment of that one grid cell, you can use <code>align-self: center</code>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Now you know how to vertically center text. Next time you see a tweet about centering a <code>div</code>, you can reply with your newfound CSS knowledge!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The CSS Flexbox Handbook – Complete Guide with Practical Examples ]]>
                </title>
                <description>
                    <![CDATA[ Flexbox is a useful tool for creating beautiful and responsive layouts for web pages. In this guide, you will learn everything you need to know to start using CSS Flexbox like a pro. We'll also go through loads of practice examples. This is a perfect... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-css-flexbox-handbook/</link>
                <guid isPermaLink="false">66d45de94a7504b7409c3359</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ handbook ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Benjamin Semah ]]>
                </dc:creator>
                <pubDate>Wed, 18 Oct 2023 17:25:54 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/10/The-CSS-Flexbox-Handbook-Cover.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Flexbox is a useful tool for creating beautiful and responsive layouts for web pages. In this guide, you will learn everything you need to know to start using CSS Flexbox like a pro. We'll also go through loads of practice examples.</p>
<p>This is a perfect resource for you if you are a beginner web developer. It'll also be useful if you're an experienced developer who wants to brush up on your responsive web design skills.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-what-is-flexbox">What is Flexbox?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-benefits-of-using-flexbox">What are the benefits of using Flexbox?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-main-axis-and-the-cross-axis">The main axis and the cross axis</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-flex-containers-and-flex-items">Flex Containers and Flex Items</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-understanding-flex-and-inline-flex">Understanding <code>Flex</code> and <code>Inline-flex</code></a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-display-flex">display: flex</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-display-inline-flex">display: inline-flex</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-container-properties">The Flex Container Properties</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-direction-property">The <code>flex-direction</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-wrap-property">The <code>flex-wrap</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-flow-shorthand-property">The <code>flex-flow</code> Shorthand Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-justify-content-property">The <code>justify-content</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-align-items-property">The <code>align-items</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-align-content-property">The <code>align-content</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-place-content-property">The <code>place-content</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#the-flex-items-properties">The Flex Items Properties</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-order-property">The <code>order</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-align-self-property">The <code>align-self</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-grow-property">The <code>flex-grow</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-shrink-property">The <code>flex-shrink</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-basis-property">The <code>flex-basis</code> Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-the-flex-shorthand-property">The <code>flex</code> Shorthand Property</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-flexbox-gaps">Flexbox Gaps</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-center-an-element-with-flexbox">How to Center an Element With Flexbox</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-practice-with-flexbox-games">Practice with Flexbox Games</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-are-there-bugs-in-css-flexbox">Are There Bugs in CSS Fexbox?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-what-is-flexbox">What is Flexbox?</h2>
<p>Flexbox is short for "Flexible Box Layout". It's a CSS layout model that simplifies creating complex layouts. It provides a flexible way to align elements and distribute space within a container element.</p>
<p>The Flexbox layout model is bidirectional. This means you can either arrange your elements in rows, columns, or both. More on that later.</p>
<h3 id="heading-what-are-the-benefits-of-using-flexbox">What are the benefits of using Flexbox?</h3>
<p>Before Flexbox, it was hard to create complex layouts and responsive web pages. You needed a combination of CSS floats and position properties. This required many workarounds and hacks.</p>
<p>But with Flexbox, you can now do the following with less difficulty and fewer lines of code:</p>
<ul>
<li><p>Align and center elements using properties like <code>justify-content</code> and <code>align-items</code>.</p>
</li>
<li><p>Develop responsive layouts without writing lots of media queries.</p>
</li>
<li><p>Reorder elements without changing the HTML structure</p>
</li>
<li><p>Create same-height columns without any extra HTML elements or background images.</p>
</li>
</ul>
<p>Now you know what Flexbox is, along with some of the things you can do with it. Let's see how you can use it.</p>
<h3 id="heading-the-main-axis-and-the-cross-axis">The main axis and the cross-axis</h3>
<p>The first thing you need to understand about Flexbox is the concept of axes. Every flex container (an element with a <code>display</code> property set to <code>flex</code> or <code>inline-flex</code>) has a main axis and a cross axis.</p>
<p>The main axis is either horizontal or vertical depending on the value of the <code>flex-direction</code>. No worries if you are not familiar with <code>flex-direction</code>. You are about to learn it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/44.-main---cross-axis.png" alt="The main axis and the cross axis when the " width="600" height="400" loading="lazy"></p>
<p><em>The cross axis and main axis when the</em> <code>flex-direction</code> is <code>row</code></p>
<p>In this example, the main axis is horizontal and the cross axis is vertical.</p>
<p>The following is an example where the the main axis is vertical and the cross axis, is horizontal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/45.-cross---main-axis.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The main axis and cross axis when the</em> <code>flex-direction</code> is <code>column</code></p>
<h2 id="heading-flex-containers-and-flex-items">Flex Containers and Flex Items</h2>
<p>To use all of Flexbox's properties, you need to set the <code>display</code> property for an element to <code>flex</code> or <code>inline-flex</code>.</p>
<p>This turns the element into a flex container, and the children of that element become flex items.</p>
<p>Here's an example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Flex Item 1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Flex Item 2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>    
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This paragraph is not a flex item<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {  
  <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<p>The <code>.container</code> element is now a flex container. The three div elements are direct children of the <code>.container</code> element, which makes them flex items.</p>
<p>But the paragraph element inside the third div is not a flex item. This is because it's not a direct child of the <code>.container</code> element.</p>
<h2 id="heading-understanding-flex-and-inline-flex">Understanding <code>flex</code> and <code>inline-flex</code></h2>
<p>You can use both <code>flex</code> and <code>inline-flex</code> to make an element a flex container. The difference is in how they interact with surrounding elements.</p>
<h3 id="heading-display-flex"><code>display: flex</code></h3>
<p>This makes the flex container behave like a block-level element. The flex-container takes up the entire available width of its parent element. It starts on a new line, and the element that comes after it also starts on a new line.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Button One<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

/* Flex Container */
<span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"gold"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"green"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Button Two<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/46.-display-flex.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex containers behave like block elements when you use</em> <code>display: flex</code></p>
<p>The <code>.container</code> element takes up the entire available width of the body (its parent element).</p>
<h3 id="heading-display-inline-flex"><code>display: inline-flex</code></h3>
<p>This makes the flex-container behave like an inline-level element. This allows other inline elements (like buttons) to flow alongside it. Using the previous example, this is how the elements will be arranged when you change <code>display</code> from <code>flex</code> to <code>inline-flex</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/47.-display-inline-flex.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex containers behave like</em> <code>inline-elements</code> when you use <code>display: inline-flex</code></p>
<p>The flex container does not take up the entire width of its parent. It uses only as much horizontal space as necessary for its content.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ug2zkz?file=style.css"><strong>Practice using flex and inline-flex</strong></a> <strong>on StackBlitz</strong></p>
<h2 id="heading-the-flex-container-properties">The Flex Container Properties</h2>
<p>The flex container properties allow you to control the layout and alignment of the flex items within a flex container.</p>
<p><strong>NOTE:</strong> You apply these properties on the flex container, and not on its items.</p>
<p>The following are the flex container properties:</p>
<ul>
<li><p><code>flex-direction</code></p>
</li>
<li><p><code>flex-wrap</code></p>
</li>
<li><p><code>flex-flow</code></p>
</li>
<li><p><code>justify-content</code></p>
</li>
<li><p><code>align-items</code></p>
</li>
<li><p><code>align-content</code></p>
</li>
<li><p><code>place-content</code></p>
</li>
</ul>
<h3 id="heading-the-flex-direction-property">The <code>flex-direction</code> Property</h3>
<p>The <code>flex-direction</code> property defines the direction for displaying the flex items. It is what sets the flex container's main axis. This property can take any of these four values:</p>
<ul>
<li><p><code>row</code> (default value)</p>
</li>
<li><p><code>column</code></p>
</li>
<li><p><code>row-reverse</code></p>
</li>
<li><p><code>column-reverse</code></p>
</li>
</ul>
<p>Now, let's look at some examples to see how it all works.</p>
<p>In the following code snippet, we have a <code>names-container</code> with four names:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"names-container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jill"</span>&gt;</span>1. JILL<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"john"</span>&gt;</span>2. JOHN<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jane"</span>&gt;</span>3. JANE<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jack"</span>&gt;</span>4. JACK<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>Let's see the different ways you can arrange the names using the <code>flex-direction</code> property.</p>
<h4 id="heading-flex-direction-row"><code>flex-direction: row</code></h4>
<p>This displays the flex-items horizontally from left to right.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: row;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/1.-flex-direction-row.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: row</code></p>
<h4 id="heading-flex-direction-column"><code>flex-direction: column</code></h4>
<p>This displays the flex-items vertically from top to bottom.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/2.-flex-direction-column.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: column</code></p>
<h4 id="heading-flex-direction-row-reverse"><code>flex-direction: row-reverse</code></h4>
<p>This is the opposite of the row value. It displays the flex items from right to left.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/3.-flex-direction-row-reverse.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: row-reverse</code></p>
<h4 id="heading-flex-direction-column-reverse"><code>flex-direction: column-reverse</code></h4>
<p>This is the opposite of the column value. It displays the flex items from the bottom to the top.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/4.-flex-direction-column-reverse.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-direction: column-reverse</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-aaerav?file=style.css"><strong>Practice using flex-direction</strong></a> <strong>on StackBlitz</strong></p>
<h4 id="heading-a-note-on-the-reverse-values-and-accessibility">A note on the reverse values and accessibility:</h4>
<p>There's something you need to keep in mind when you use <code>row-reverse</code> and <code>column-reverse</code>. As you've already seen, both affect the visual order of elements on the screen.</p>
<p>But the order in your HTML remains unchanged. And that is the order that screen readers and keyboard navigation controls use.</p>
<p>In the example, when you use <code>row-reverse</code>, you see Jack's name first on the screen, followed by Jane, John, and Jill.</p>
<p>But for someone using a screen reader, they will hear the names as they appear in the HTML and not as they appear on screen. In this case, they will first hear Jill's name, followed by John, Jane, and Jack.</p>
<h3 id="heading-the-flex-wrap-property">The <code>flex-wrap</code> Property</h3>
<p>Sometimes, the space within the flex container will not be enough for the flex items.</p>
<p>In such cases, you use the <code>flex-wrap</code> property to choose whether to let the flex-items overflow or begin on a new line.</p>
<p>The <code>flex-wrap</code> property accepts any of the following values:</p>
<ul>
<li><p><code>nowrap</code> (default value)</p>
</li>
<li><p><code>wrap</code></p>
</li>
<li><p><code>wrap-reverse</code></p>
</li>
</ul>
<p>To see <code>flex-wrap</code> in action, let's add four more names to our <code>names-container</code>:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"names-container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jill"</span>&gt;</span>1. JILL<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"john"</span>&gt;</span>2. JOHN<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jane"</span>&gt;</span>3. JANE<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"jack"</span>&gt;</span>4. JACK<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sara"</span>&gt;</span>5. SARA<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"seth"</span>&gt;</span>6. SETH<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"seal"</span>&gt;</span>7. SEAL<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h4 id="heading-flex-wrap-nowrap"><code>flex-wrap: nowrap</code></h4>
<p>This keeps all the flex items on a single line either in a row or column. It allows the flex items to overflow if there's not enough room in the flex container. See the example below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: row;  
    <span class="hljs-attribute">flex-wrap</span>: nowrap;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/5.-flex-wrap-nowrap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex items overflows because</em> <code>flex-wrap</code> is set to <code>nowrap</code></p>
<p>In this example, three names overflow out of the container because there is not enough space for them.</p>
<h4 id="heading-flex-wrap-wrap"><code>flex-wrap: wrap</code></h4>
<p>This will wrap or push the flex items to the next line if there's not enough room for them.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/6.-flex-wrap-wrap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Flex items wrap or moves to the next line when</em> <code>flex-wrap</code> is set to <code>wrap</code></p>
<h4 id="heading-flex-wrap-wrap-reverse"><code>flex-wrap: wrap-reverse</code></h4>
<p>This is the opposite of <code>wrap</code>. It moves the overflow items to the next line but in a reverse direction.</p>
<p>For example, using <code>wrap-reverse</code> on the names container moves overflow items to the next top line instead of the next line below.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/7.-flex-wrap-wrap-reverse.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-wrap: wrap-reverse</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cbmfgr?file=style.css"><strong>Practice using flex-wrap</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-flow-shorthand-property">The <code>flex-flow</code> Shorthand Property</h3>
<p>The <code>flex-flow</code> property is a shorthand for the <code>flex-direction</code> and <code>flex-wrap</code> properties. This means that when you use <code>flex-flow</code>, you can apply both properties with only a single line of code.</p>
<p>See the example below using the names container. You can give the container <code>flex-direction</code> and <code>flex-wrap</code> properties.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: column;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;
}
</code></pre>
<p>Or you can use the <code>flex-flow</code> shorthand to get the same result.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-flow</span>: column wrap;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/8.-flex-flow.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-flow: column wrap</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-xuv4bx?file=style.css"><strong>Practice using flex-flow</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-justify-content-property">The <code>justify-content</code> Property</h3>
<p>This <code>justify-content</code> property handles the alignment of flex items on the main axis of the flex container.</p>
<p>You can use it to take care of how space is distributed on the main axis. This property takes any of the following values:</p>
<ul>
<li><p><code>flex-start</code> (default value)</p>
</li>
<li><p><code>flex-end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
</ul>
<h4 id="heading-justify-content-flex-start"><code>justify-content: flex-start</code></h4>
<p>This places the items at the start of the flex-direction. If the main axis is horizontal with a <code>flex-direction</code> of <code>row</code> (like the example below), it aligns the items to the left. And if it's vertical (with a <code>flex-direction</code> of <code>column</code>), it aligns the items to the top.</p>
<p>Using the names container example, this is how <code>justify-content: flex-start</code> would look like:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: flex-start;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/9.-justify-content-flex-start.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: flex-start</code></p>
<h4 id="heading-justify-content-flex-end"><code>justify-content: flex-end</code></h4>
<p>This will place the flex items at the end of the flex-direction of the main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/10.-justify-content-flex-end.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: flex-end</code></p>
<h4 id="heading-justify-content-center"><code>justify-content: center</code></h4>
<p>This places the flex items at the center of the flex container's main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/11.-justify-content-center-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: center</code></p>
<h4 id="heading-justify-content-space-between"><code>justify-content: space-between</code></h4>
<p>This will place the first flex item at the start of the main axis. And also place the last item at the end of the main axis. Then space on the main axis is distributed equally among the the elements.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/12.-justify-content-space-between.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: space-between</code></p>
<h4 id="heading-justify-content-space-evenly"><code>justify-content: space-evenly</code></h4>
<p>This distributes space equally among the flex items. This means the space before and after each item is the same.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/13.-justify-content-space-evenly.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: space-evenly</code></p>
<h4 id="heading-justify-content-space-around"><code>justify-content: space-around</code></h4>
<p>This also distributes space equally between the flex items. The key difference here is that the space before the first item and after the last item is half the space between the flex items.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/14.-justify-content-space-around.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>justify-content: space-around</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-zpcbxv?file=style.css"><strong>Practice using justify-content</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-align-items-property">The <code>align-items</code> Property</h3>
<p>The <code>align-items</code> property handles the alignment of flex items on the cross-axis of the flex container. It can take any of the following values:</p>
<ul>
<li><p><code>stretch</code> (default value)</p>
</li>
<li><p><code>flex-start</code></p>
</li>
<li><p><code>flex-end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>baseline</code></p>
</li>
</ul>
<h4 id="heading-align-items-stretch"><code>align-items: stretch</code></h4>
<p>This stretches the flex items to fill up the space within the flex-container.</p>
<p>See the example below using a new names container with name cards of different sizes:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: stretch;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/15.-align-items-stretch.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: stretch</code></p>
<h4 id="heading-align-items-flex-start"><code>align-items: flex-start</code></h4>
<p>This will place the flex items at the start of the cross-axis of the flex container. If the cross-axis is vertical like in the example below, <code>align-items: flex-start</code> will place the items at the top.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: flex-start;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/16.-align-items-flex-start.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: flex-start</code></p>
<h4 id="heading-align-items-flex-end"><code>align-items: flex-end</code></h4>
<p>This will place the flex items at the end of the cross-axis of the flex container. If the cross-axis is vertical like in the example below, <code>align-items: flex-end</code> will place the items at the bottom.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: flex-end;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/17.-align-items-flex-end.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: flex-end</code></p>
<h4 id="heading-align-items-center"><code>align-items: center</code></h4>
<p>This aligns flex items at the center of the cross-axis of the flex container.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: center;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/18.-align-items-center.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-items: center</code></p>
<h4 id="heading-align-items-baseline"><code>align-items: baseline</code></h4>
<p>When you use the <code>baseline</code> value, flex items are arranged such that their baselines are aligned. See the example below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: baseline;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/Untitled-design-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The baseline is indicated with the dotted white line</em></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-jydywf?file=style.css"><strong>Practice using align-items</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-align-content-property">The <code>align-content</code> Property</h3>
<p>When you have a flex container with wrap (or more than one flex line), you may need to align the lines to distribute the space as you want. That is when you use <code>align-content</code>. This property can take any of the following values:</p>
<ul>
<li><p><code>stretch</code> (default value)</p>
</li>
<li><p><code>flex-start</code></p>
</li>
<li><p><code>flex-end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
</ul>
<p>In the example below, there are 11 names in the names container. And the names container element has a <code>flex-wrap</code> value of <code>wrap</code>. This means you can apply the <code>align-content</code> property to change the alignment of the flex lines.</p>
<h4 id="heading-align-content-stretch"><code>align-content: stretch</code></h4>
<p>This stretches the flex lines to fill up the space within the flex container's cross-axis.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">align-items</span>: stretch;  
    <span class="hljs-comment">/* Other styles here... */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/20.-align-content-stretch.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: stretch</code></p>
<h4 id="heading-align-content-flex-start"><code>align-content: flex-start</code></h4>
<p>This places the flex lines at the start of the container's cross-axis. For example, if the cross axis is vertical like that of the names container, it will place the flex lines at the top.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/21.-align-content-flex-start.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: flex-start</code></p>
<h4 id="heading-align-content-flex-end"><code>align-content: flex-end</code></h4>
<p>This places the flex lines at the end of the container's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/22.-align-content-flex-end.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: flex-end</code></p>
<h4 id="heading-align-content-center"><code>align-content: center</code></h4>
<p>This places the flex lines at the center of the container's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/23.-align-content-center.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: center</code></p>
<h4 id="heading-align-content-space-between"><code>align-content: space-between</code></h4>
<p>This will place the first flex line at the start of the cross-axis. It also places the last flex line at the end of the cross axis. Then space on the cross-axis is distributed equally between the the lines.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/24.-align-content-space-between.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: space-between</code></p>
<h4 id="heading-align-content-space-evenly"><code>align-content: space-evenly</code></h4>
<p>This distributes space equally between the flex lines. This means the space before and after each line is the same.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/25.-align-content-space-evenly.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: space-evenly</code></p>
<h4 id="heading-align-content-space-around"><code>align-content: space-around</code></h4>
<p>This also distributes space equally between the flex lines. The key difference here is the space before the first line and after the last line is half the space between the flex lines.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/26.-align-content-space-around.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-content: space-around</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-fukvgd?file=style.css"><strong>Practice using align-content</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-place-content-property">The <code>place-content</code> Property</h3>
<p>If you need to use both the <code>justify-content</code> and <code>align-content</code> properties, you use the <code>place-content</code> shorthand property.</p>
<p>It can take one or two values. When you give it a single value, the browser will apply the same value for both <code>justify-content</code> and <code>align-content</code>.</p>
<p>And when you give 2 values for <code>place-content</code>, the first value will be for <code>align-content</code> and the second for <code>justify-content</code>.</p>
<p>Let's look at an example:</p>
<p>Instead of writing this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">align-content</span>: flex-end;  
    <span class="hljs-attribute">justify-content</span>: flex-start;  
    <span class="hljs-comment">/* Other content */</span>
}
</code></pre>
<p>You can instead write the following and it will have the same effect:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">place-content</span>: flex-end flex-start;  
    <span class="hljs-comment">/* Other content */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/43.-place-content.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using the</em> <code>place-content</code> shorthand</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ytdywl?file=style.css"><strong>Practice using place-content</strong></a> <strong>on StackBlitz.</strong></p>
<h2 id="heading-the-flex-item-properties">The Flex Item Properties</h2>
<p>Every direct child of a flex container is a flex item. So far, you've learned the properties of the flex containers.</p>
<p>Flexbox also has properties that you can apply to individual flex items. They include the following:</p>
<ul>
<li><p><code>order</code></p>
</li>
<li><p><code>align-self</code></p>
</li>
<li><p><code>flex-grow</code></p>
</li>
<li><p><code>flex-shrink</code></p>
</li>
<li><p><code>flex-basis</code></p>
</li>
<li><p><code>flex</code></p>
</li>
</ul>
<h3 id="heading-the-order-property">The <code>order</code> property</h3>
<p>The <code>order</code> property determines the order of appearance for the flex items.</p>
<p>The value you give to this property must be a number. A flex item with a lower number will appear before one with a higher number.</p>
<p>In the HTML code, the order for the four names is as follows:</p>
<ol>
<li><p>Jill</p>
</li>
<li><p>John</p>
</li>
<li><p>Jane</p>
</li>
<li><p>Jack</p>
</li>
</ol>
<pre><code class="lang-css">&lt;<span class="hljs-selector-tag">div</span> <span class="hljs-selector-tag">class</span>="<span class="hljs-selector-tag">names-container</span>"&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">jill</span>"&gt;1. <span class="hljs-selector-tag">JILL</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">john</span>"&gt;2. <span class="hljs-selector-tag">JOHN</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">jane</span>"&gt;3. <span class="hljs-selector-tag">JANE</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
    &lt;<span class="hljs-selector-tag">p</span> <span class="hljs-selector-tag">id</span>="<span class="hljs-selector-tag">jack</span>"&gt;4. <span class="hljs-selector-tag">JACK</span>&lt;/<span class="hljs-selector-tag">p</span>&gt;
&lt;/<span class="hljs-selector-tag">div</span>&gt;
</code></pre>
<p>You can change the order of appearance on the screen using the <code>order</code> property. See the example below.</p>
<p>Here's how they appear with no <code>order</code> properties:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/27.-no-order-property.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Name cards before add the</em> <code>order</code> property</p>
<p>Now, see how they appear when you add the following order properties:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-id">#jill</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">2</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fe4f46</span>;
}

<span class="hljs-selector-id">#john</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">4</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fcd65c</span>;
}

<span class="hljs-selector-id">#jane</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">1</span>;  
    <span class="hljs-attribute">background-color</span>: 
    <span class="hljs-number">#00bab4</span>;
}

<span class="hljs-selector-id">#jack</span> {  
    <span class="hljs-attribute">order</span>: <span class="hljs-number">3</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#003f54</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/28.-with-order-property.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The</em> <code>order</code> property changes the order of appearance</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-c5mf8q?file=style.css"><strong>Practice using the order property</strong></a> <strong>on StackBlitz.</strong></p>
<p><strong>Word of caution:</strong> Even though the order of appearance changes on screen, the order in the HTML remains unchanged. And it's the order in the HTML that screen readers use. Where possible, it's best practice to change the order in the HTML rather than doing it with Flexbox.</p>
<h3 id="heading-the-align-self-property">The <code>align-self</code> property</h3>
<p>You can use the <code>align-self</code> property to give a flex item a different alignment from the other items.</p>
<p>It works the same way as the <code>align-items</code> property. The difference is that whereas <code>align-items</code> applies to all flex items, the <code>align-self</code> property is applied to only specific items.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">align-items</span>: center;  
    <span class="hljs-comment">/* Other styles */</span>    
}

<span class="hljs-selector-id">#jill</span> {
    <span class="hljs-attribute">align-self</span>: flex-start;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/37.-align-self.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>align-self</code> with a <code>flex-start</code> value</p>
<p>In the example, the <code>align-items</code> property for the names container has a value of <code>center</code>. This aligns all the names at the center.</p>
<p>But using the <code>align-self</code> property, you are able to align Jill's name card to the top with a value of <code>flex-start</code>.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-e9ctpu?file=style.css"><strong>Practice using the align-self property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-grow-property">The <code>flex-grow</code> property</h3>
<p>When you set a container's display to <code>flex</code>, often there will be some extra space after the items are arranged. See the example below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: 
    flex-start;  
     <span class="hljs-comment">/* Other styles */</span>
 }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/29.-flex-grow-extra-space.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The flex container has more than enough space for the flex items</em></p>
<p>The browser treats the extra as a value of <code>1</code>. This means when you give a <code>flex-grow</code> value of <code>0.5</code> to only one of the flex items, the browser will add half of the remaining space to the item's size.</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#jill</span> {
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">0.5</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/30.-flex-grow-0.5.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The</em> <code>flex-grow</code> property makes the Jill's larger than its initial size</p>
<p>And if you add a <code>flex-grow</code> value of <code>1</code> to <strong>only one of the flex items</strong>, the browser will add all the extra space to that item.</p>
<p><strong>NOTE:</strong> If only one item in the container has a <code>flex-grow</code> value, then any value of 1 or more will make it take up all the extra space.</p>
<p>For example, the two code snippets below will have the same effect on Jill's card:</p>
<pre><code class="lang-css"><span class="hljs-selector-id">#jill</span> {  
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">1</span>;
}
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-id">#jill</span> {  
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">99</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/31.-flex-grow-1-or-more.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>When only one card has a</em> <code>flex-grow</code> of <code>1</code> or more</p>
<p>What happens when you add <code>flex-grow</code> values to more than one element?</p>
<p>The browser will share the extra space proportionately for them.</p>
<p>For example, when you give Jane a <code>flex-grow</code> of <code>3</code> and Jack a <code>flex-grow</code> of <code>1</code>, the browser will share the extra space with a <code>3:1</code> ratio.</p>
<p>This means the total value of the extra space becomes <code>4</code> (3+1). <code>Jane</code> will then get <code>3/4</code> of the extra space. And <code>Jack</code> will get <code>1/4</code> of it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/32.-flex-grow-jane-jack.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The extra space is shared proportionately betwee</em> <code>Jane</code> and <code>Jack</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-m6h8af?file=style.css"><strong>Practice using the flex-grow property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-shrink-property">The <code>flex-shrink</code> property</h3>
<p>The <code>flex-shrink</code> property is the opposite of <code>flex-grow</code>.</p>
<p>You use <code>flex-grow</code> when you want to increase the flex item's size if there's extra space. But, you use <code>flex-shrink</code> when you want to decrease the flex-item's size if there's not enough space in the flex container.</p>
<p>See the example below:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"numbers-container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"one"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"two"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"three"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"four"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.numbers-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: flex-start;  
    <span class="hljs-comment">/* Other styles */</span>
}

<span class="hljs-selector-id">#one</span> {  
    <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">2</span>;  
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#fe4f46</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/33.-flex-shrink-value-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The first card shrinks to make room for the others</em></p>
<p>In the example, each of the four numbers has a width of 150px (that's a total of 600px). But the <code>numbers-container</code> has a width of 400px which is not enough.</p>
<p>The cards have to shrink to fit in the available space. But Number <code>1</code> which with a <code>flex-shrink</code> value of 2 shrinks to become twice as small as the other numbers.</p>
<h4 id="heading-what-if-you-dont-want-a-flex-item-to-shrink">What if you don't want a flex item to shrink?</h4>
<p>To prevent a flex item from shrinking, give it a <code>flex-shrink</code> value of <code>0</code>.</p>
<p>For example, when you give Number <code>1</code> a <code>flex-shrink</code> of <code>0</code>, it will maintain the width of 150px. And the other flex items will shrink to fit in the remaining space.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/34.-flex-shrink-vallue-0.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The first card does not shrink because it has a</em> <code>flex-shrink</code> value of <code>0</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-q9zndc?file=style.css"><strong>Practice using the flex-shrink property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-basis-property">The <code>flex-basis</code> property</h3>
<p>You can use the <code>flex-basis</code> property to set the default length of a specific flex item. This is either the width or height of the item depending on the <code>flex-direction</code>.</p>
<p>If the <code>flex-direction</code> is <code>row</code> or <code>row-reverse</code>, the value for <code>flex-basis</code> becomes the initial width of the item.</p>
<p>And if <code>flex-direction</code> is <code>column</code> or <code>column-reverse</code>, then the value for <code>flex-basis</code> becomes the initial height of the item.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: column;  
    <span class="hljs-comment">/* Other styles */</span>
}

<span class="hljs-selector-tag">div</span> {  
    <span class="hljs-attribute">height</span>: <span class="hljs-number">20px</span>;
}

<span class="hljs-selector-id">#jane</span> {  
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">60px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/35.-flex-basis-height.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-basis</code> setting the height of an item</p>
<p>In the example, the height for the divs is set at 20px. But Jane gets a <code>flex-basis</code> value of 60px. And that overrides the 20px given to all the divs.</p>
<p><strong>Note:</strong> The flex-basis of 60px becomes the height for Jane because the <code>flex direction</code> is <code>column</code>. This means the main axis is vertical.</p>
<p>Here is another example. This time, the <code>flex-direction</code> is <code>row</code>. This means the <code>flex-basis</code> will set the width of the item.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-direction</span>: row;  
    <span class="hljs-comment">/* Other styles */</span>
}

<span class="hljs-selector-tag">div</span> {  
    <span class="hljs-attribute">width</span>: <span class="hljs-number">70px</span>;
}

<span class="hljs-selector-id">#jane</span> {  
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">140px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/36.-flex-basis-width.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of</em> <code>flex-basis</code> setting the width of an item</p>
<p>While all the other divs have a width of 70px, Jane has a width of 140px set by the <code>flex-basis</code>.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-maihzd?file=style.css"><strong>Practice using the flex-basis property</strong></a> <strong>on StackBlitz.</strong></p>
<h3 id="heading-the-flex-shorthand-property">The <code>flex</code> Shorthand Property</h3>
<p>You can use <code>flex</code> as a shorthand for the <code>flex-grow</code>, <code>flex-shrink</code>, and <code>flex-basis</code> properties.</p>
<p>For example, instead of writing the following:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item</span> {  
    <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">2</span>;  
    <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">0</span>;  
    <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">50px</span>;
}
</code></pre>
<p>You can use the shorthand like so and it will have the same effect:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item</span> {  
    <span class="hljs-attribute">flex</span>: <span class="hljs-number">2</span> <span class="hljs-number">0</span> <span class="hljs-number">50px</span>;
}
</code></pre>
<p>The <code>flex</code> property can take up to three values. The order of the values is important. The browser assigns the first value for <code>flex-grow</code>, the second for <code>flex-shrink</code>, and the third for <code>flex-basis</code>.</p>
<p>The default values for <code>flex</code> are <code>1 0 auto</code>.</p>
<p>This means if you give <code>flex</code> a single value of 2, the browser uses 2 for <code>flex-grow</code>. And then it sets <code>flex-shrink</code> to 0 and <code>flex-basis</code> to auto.</p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-m19hov?file=style.css"><strong>Practice using the</strong> <code>flex</code> property</a> <strong>on StackBlitz.</strong></p>
<h2 id="heading-how-to-center-an-element-with-flexbox">How to Center an Element With Flexbox</h2>
<p>One of the headaches for many front-end developers is centering elements. Flexbox has a perfect solution for that.</p>
<p>There are two steps involved.</p>
<ol>
<li><p>Make the parent element a flex container by setting <code>display</code> to <code>flex</code>.</p>
</li>
<li><p>Give a value of <code>center</code> to both <code>justify-content</code> and <code>align-items</code>.</p>
</li>
</ol>
<p>That's it! Your element will be perfectly centered.</p>
<p>Example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"name-container"</span>&gt;</span>  
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>JOHN<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.name-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">justify-content</span>: center;  
    <span class="hljs-attribute">align-items</span>: center;  
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/38.-center-element-w--flexbox.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of centering an element with Flexbox</em></p>
<p>Whether you're trying to center text, images, or even an entire navigation bar, this will work just fine.</p>
<h2 id="heading-flexbox-gaps">Flexbox Gaps</h2>
<p>You can use the <code>gap</code> property to adjust the space between flex items.</p>
<p><strong>NOTE:</strong> You apply the gap property on the flex container and not the flex items.</p>
<p><code>gap</code> can take two values: the first value for gaps between the rows and the second value for gaps between the columns.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">gap</span>: <span class="hljs-number">50px</span> <span class="hljs-number">10px</span>; 
    <span class="hljs-comment">/* row-gap column-gap */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/39.-gap-two-values.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of giving two values for the gap property</em></p>
<p>If the gap you want between the rows and the columns is the same, you can use a single value. The browser will apply the same value to both rows and columns.</p>
<p>Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">gap</span>: <span class="hljs-number">10px</span>; 
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/40.-gap-single-value.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using only one value for both rows and columns gap</em></p>
<p>You can also use the properties <code>row-gap</code> if you need to apply a specific gap value between only the rows. and <code>column-gap</code> if you need to add gaps between only the columns.</p>
<p>Example: Adding gaps between only the rows:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">row-gap</span>: <span class="hljs-number">20px</span>; 
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/41.-row-gap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using</em> <code>row-gap</code></p>
<p>Example: Adding gaps between only the columns:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.names-container</span> {  
    <span class="hljs-attribute">display</span>: flex;  
    <span class="hljs-attribute">flex-wrap</span>: wrap;  
    <span class="hljs-attribute">column-gap</span>: <span class="hljs-number">20px</span>; 
    <span class="hljs-comment">/* Other Styles */</span>
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/08/42.-column-gap.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Example of using</em> <code>column-gap</code></p>
<p><a target="_blank" href="https://stackblitz.com/edit/js-v77toh?file=style.css"><strong>Practice using the gap property</strong></a> <strong>on StackBlitz.</strong></p>
<h2 id="heading-practice-with-flexbox-games">Practice with Flexbox Games</h2>
<p>Want to practice Flexbox in an interactive way? Check out the following games. They provide a hands-on experience for practicing Flexbox in a fun and engaging way.</p>
<ul>
<li><p><a target="_blank" href="https://flexboxfroggy.com/">Flexbox Froggy</a></p>
</li>
<li><p><a target="_blank" href="http://www.flexboxdefense.com/">Flexbox Defense</a></p>
</li>
<li><p><a target="_blank" href="https://mastery.games/flexboxzombies/">Flexbox Zombies</a></p>
</li>
</ul>
<h2 id="heading-are-there-bugs-in-css-flexbox">Are There Bugs in CSS Flexbox?</h2>
<p>While CSS Flexbox is a powerful layout tool, it's got a few bugs that may surprise you.</p>
<p>A common example is that <strong>some HTML elements cannot act as flex containers</strong>. These include the <code>&lt;button&gt;</code>, <code>&lt;fieldset&gt;</code>, and <code>&lt;summary&gt;</code> elements.</p>
<p>The workaround is to use an element like a <code>div</code> to wrap around the element's children. Then use Flexbox on the wrapper <code>div</code>.</p>
<p>If you are curious about other Flexbox bugs and workarounds, you can have a look at <a target="_blank" href="https://github.com/philipwalton/flexbugs">the Flexbugs repository</a> on GitHub.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this guide, you learned all the Flexbox properties, their values, and how to use them to create responsive layouts. You also learned about some games like Flexbox Froggy you can use for practice.</p>
<p>Thank you for reading, and happy coding! For more in-depth tutorials, feel free to <a target="_blank" href="https://www.youtube.com/@DevAfterHours">subscribe to my YouTube channel</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Flexbox Explained – Complete Guide to Flexible Containers and Flex Items ]]>
                </title>
                <description>
                    <![CDATA[ CSS Flexbox gives you the tools to create basic and advanced website layouts in flexible and responsive ways. This tutorial discusses everything you need to know to use Flexbox like a pro. Table of Contents What Is Flexbox? Flex Container vs. Flex I... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-flexbox-complete-guide/</link>
                <guid isPermaLink="false">66ba0de6256f04965e2bd0c0</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Oluwatobi Sofela ]]>
                </dc:creator>
                <pubDate>Fri, 28 Oct 2022 14:28:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/css-flexbox-complete-guide-codesweetly-pexels-chris-f-6664375.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CSS Flexbox gives you the tools to create basic and advanced website layouts in flexible and responsive ways.</p>
<p>This tutorial discusses everything you need to know to use Flexbox like a pro.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><a class="post-section-overview" href="#heading-what-is-flexbox">What Is Flexbox?</a></li>
<li><a class="post-section-overview" href="#heading-flex-container-vs-flex-item-whats-the-difference">Flex Container vs. Flex Item: What's the Difference?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-a-flex-value-in-css">What Is a <code>flex</code> Value in CSS?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-an-inline-flex-value-in-css">What Is an <code>inline-flex</code> Value in CSS?</a></li>
<li><a class="post-section-overview" href="#heading-properties-for-specifying-flexboxs-layout">Properties for Specifying Flexbox's Layout</a></li>
<li><a class="post-section-overview" href="#heading-what-are-the-flexible-containers-properties">What Are the Flexible Containers Properties?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-direction-property">What Is Flexbox's <code>flex-direction</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-wrap-property">What Is Flexbox's <code>flex-wrap</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-flow-property">What Is Flexbox's <code>flex-flow</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-justify-content-property">What Is Flexbox's <code>justify-content</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-align-items-property">What Is Flexbox's <code>align-items</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-align-content-property">What Is Flexbox's <code>align-content</code> Property?</a></li>
<li><a class="post-section-overview" href="#what-are-the-flexible-items-properties">What Are the Flexible Items Properties?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-align-self-property">What Is Flexbox's <code>align-self</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-order-property">What Is Flexbox's <code>order</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-grow-property">What Is Flexbox's <code>flex-grow</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-shrink-property">What Is Flexbox's <code>flex-shrink</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-basis-property">What Is Flexbox's <code>flex-basis</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-what-is-flexboxs-flex-property">What Is Flexbox's <code>flex</code> Property?</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-elements-horizontally-with-flexbox">How to Center Elements Horizontally with Flexbox</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-elements-vertically-with-flexbox">How to Center Elements Vertically with Flexbox</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-elements-horizontally-and-vertically-with-flexbox">How to Center Elements Horizontally and Vertically with Flexbox</a></li>
<li><a class="post-section-overview" href="#heading-overview">Overview</a></li>
</ol>
<p>So, without any further ado, let's understand what Flexbox is.</p>
<h2 id="heading-what-is-flexbox">What Is Flexbox?</h2>
<p><strong>Flexbox</strong> makes browsers display selected HTML elements as flexible <a target="_blank" href="https://codesweetly.com/css-box-model">box models</a>.</p>
<p>Flexbox allows easy resizing and repositioning of a flexible container and its items one-dimensionally.</p>
<p><strong>Note:</strong></p>
<ul>
<li>"One-dimensionally" means Flexbox allows laying out box models in a row or column at a time. In other words, Flexbox cannot lay out box models in a row and column at the same time.</li>
<li>Flexbox is sometimes called a flexible box layout module.</li>
<li>Use the <a target="_blank" href="https://codesweetly.com/css-grid-explained">grid layout module</a> if you need to resize and reposition elements two-dimensionally.</li>
</ul>
<h2 id="heading-flex-container-vs-flex-item-whats-the-difference">Flex Container vs. Flex Item: What's the Difference?</h2>
<p>A <strong>flex container</strong> is an <a target="_blank" href="https://codesweetly.com/web-tech-terms-h#html-element">HTML element</a> whose <a target="_blank" href="https://codesweetly.com/css-display-property"><code>display</code></a> property's value is <code>flex</code> or <code>inline-flex</code>.</p>
<p><strong>Flex items</strong> are the direct children of a flex container.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-flex-container-flex-item-illustration-codesweetly.png" alt="Illustration of a flex container and a flex item" width="600" height="400" loading="lazy">
<em>A flex container (the large yellow area in the image) is an HTML element whose display property's value is flex or inline-flex. Flex items (the smaller boxes within the yellow container) are the direct children of a flex container.</em></p>
<h2 id="heading-what-is-a-flex-value-in-css">What Is a <code>flex</code> Value in CSS?</h2>
<p><code>flex</code> tells browsers to display the selected HTML element as a block-level flexible box model.</p>
<p>In other words, setting an element's <code>display</code> property's value to <code>flex</code> turns the box model into a <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements">block-level</a> flexbox.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-gctvuc?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>flex</code> value to convert the HTML document's <code>&lt;section&gt;</code> elements from regular <code>&lt;section&gt;</code> nodes to block-level flexible box models.</p>
<p><strong>Note:</strong></p>
<ul>
<li>Converting an HTML node to a flexible box model makes the element's direct children become flexible items.</li>
<li>The <code>display: flex</code> directive only affects a box model and its direct children. It does not affect grandchildren nodes.</li>
</ul>
<p>Let's now discuss <code>inline-flex</code>.</p>
<h2 id="heading-what-is-an-inline-flex-value-in-css">What Is an <code>inline-flex</code> Value in CSS?</h2>
<p><code>inline-flex</code> tells browsers to display the selected HTML element as an inline-level flexible box model.</p>
<p>In other words, setting an element's <code>display</code> property's value to <code>inline-flex</code> turns the box model into an <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements">inline-level</a> flexbox.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: inline-flex;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ksagv8?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>inline-flex</code> value to convert the HTML document's <code>&lt;section&gt;</code> elements from regular <code>&lt;section&gt;</code> nodes to inline-level flexible box models.</p>
<p><strong>Note:</strong></p>
<ul>
<li>Converting an HTML node to a flexible box model makes the element's direct children become flexible items.</li>
<li>The <code>display: inline-flex</code> directive only affects a box model and its direct children. It does not affect grandchildren nodes.</li>
</ul>
<h2 id="heading-properties-for-specifying-flexboxs-layout">Properties for Specifying Flexbox's Layout</h2>
<p>On converting a regular HTML element to a <code>flex</code> (or <code>inline-flex</code>) box model, Flexbox provides two categories of properties for positioning the flexible box and its direct children:</p>
<ul>
<li>Flexible containers properties</li>
<li>Flexible items properties</li>
</ul>
<h2 id="heading-what-are-the-flexible-containers-properties">What Are the Flexible Containers Properties?</h2>
<p>A flexible container's properties specify how browsers should layout items within the flexible box model.</p>
<p><strong>Note:</strong> We define a flexible container's property on the flex container, not its items.</p>
<p>The six (6) types of flex container properties are:</p>
<ul>
<li><code>flex-direction</code></li>
<li><code>flex-wrap</code></li>
<li><code>flex-flow</code></li>
<li><code>justify-content</code></li>
<li><code>align-items</code></li>
<li><code>align-content</code></li>
</ul>
<p>Let's discuss the six types now.</p>
<h2 id="heading-what-is-flexboxs-flex-direction-property">What Is Flexbox's <code>flex-direction</code> Property?</h2>
<p><strong>flex-direction</strong> tells browsers the specific direction (row or column) they should lay out a flexible container's direct children.</p>
<p>In other words, <code>flex-direction</code> defines a flexbox's <a target="_blank" href="https://codesweetly.com/css-flex-direction-property#main-axis-vs-cross-axis-whats-the-difference">main axis</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-flexbox-main-axis-cross-axis-illustration-codesweetly.png" alt="Illustration of a flexbox's main and cross-axis" width="600" height="400" loading="lazy">
<em>A Flexbox's main axis is the layout orientation defined by a flex-direction property. Its cross axis is the perpendicular orientation to the main axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-direction</span>: column;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-jtpqir?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above organized the flexible <code>&lt;section&gt;</code> containers' items in the column direction of your browser's default language.</p>
<p><strong>Tip:</strong> Use <code>flex-direction: column-reverse</code> (or <code>flex-direction: row-reverse</code>) to reverse the browser's layout direction.</p>
<h2 id="heading-what-is-flexboxs-flex-wrap-property">What Is Flexbox's <code>flex-wrap</code> Property?</h2>
<p><strong>flex-wrap</strong> specifies whether browsers should wrap overflown flexible items onto multiple lines.</p>
<p>The <code>flex-wrap</code> property accepts the following values:</p>
<ul>
<li><code>nowrap</code></li>
<li><code>wrap</code></li>
<li><code>wrap-reverse</code></li>
</ul>
<p>Let's discuss the three values.</p>
<h3 id="heading-what-is-flex-wrap-nowrap-in-css-flexbox">What is <code>flex-wrap: nowrap</code> in CSS flexbox?</h3>
<p><code>nowrap</code> is <code>flex-wrap</code>'s default value. It forces all items within a flexible container into a single line (that is, row-wise or column-wise direction).</p>
<p>In other words, <code>nowrap</code> tells browsers <em>not</em> to wrap a flexible container's items.</p>
<p><strong>Note:</strong> Suppose the total width (or height) of all the items in a flexible container is greater than the flexbox's width (or height). In such a case, <code>nowrap</code> will cause the elements to overflow out of the container.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">130px</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: nowrap;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-yn6yw8?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used <code>nowrap</code> to force browsers to lay out the flexible containers' items in a single line.</p>
<h3 id="heading-what-is-flex-wrap-wrap-in-css-flexbox">What is <code>flex-wrap: wrap</code> in CSS flexbox?</h3>
<p><code>wrap</code> moves all overflow items within a flexible container to the next line.</p>
<p>In other words, <code>wrap</code> tells browsers to wrap a flexible container's overflow items.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">130px</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-78ez1m?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used <code>wrap</code> to wrap the flexible containers' overflow items to the next line.</p>
<h3 id="heading-what-is-flex-wrap-wrap-reverse-in-css-flexbox">What is <code>flex-wrap: wrap-reverse</code> in CSS flexbox?</h3>
<p><code>wrap-reverse</code> moves all overflow items within a flexible container to the next line in reverse order.</p>
<p><strong>Note:</strong> <code>wrap-reverse</code> does the same thing as <code>wrap</code>—but in reverse order.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">130px</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap-reverse;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-eyqxtf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used <code>wrap-reverse</code> to wrap the flexible containers' overflow items to the next line in reverse order.</p>
<h2 id="heading-what-is-flexboxs-flex-flow-property">What Is Flexbox's <code>flex-flow</code> Property?</h2>
<p><strong>flex-flow</strong> is a shorthand for the <code>flex-direction</code> and <code>flex-wrap</code> properties.</p>
<p>In other words, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-direction</span>: column;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
}
</code></pre>
<p>You can alternatively use the <code>flex-flow</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-flow</span>: column wrap;
}
</code></pre>
<h2 id="heading-what-is-flexboxs-justify-content-property">What Is Flexbox's <code>justify-content</code> Property?</h2>
<p><strong>justify-content</strong> specifies how browsers should position a flexible container's items along the flexbox's <a target="_blank" href="https://codesweetly.com/css-flex-direction-property#main-axis-vs-cross-axis-whats-the-difference">main axis</a>.</p>
<p>The <code>justify-content</code> property accepts the following values:</p>
<ul>
<li><code>flex-start</code></li>
<li><code>center</code></li>
<li><code>flex-end</code></li>
<li><code>space-between</code></li>
<li><code>space-around</code></li>
<li><code>space-evenly</code></li>
</ul>
<p>Let's discuss these six values.</p>
<h3 id="heading-what-is-justify-content-flex-start-in-css-flexbox">What is <code>justify-content: flex-start</code> in CSS Flexbox?</h3>
<p><code>flex-start</code> is <code>justify-content</code>'s default value. It aligns a flexible container's items with the main-start edge of the flexbox's main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-justify-content-flex-start-illustration-codesweetly.png" alt="Illustration of justify-content's flex-start value" width="600" height="400" loading="lazy">
<em>flex-start aligns a flexible container's items with the main-start side of the flexbox's main axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: flex-start;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ma7svj?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>flex-start</code> value to align the flexible container's items to the flexbox's main-start edge.</p>
<h3 id="heading-what-is-justify-content-center-in-css-flexbox">What is <code>justify-content: center</code> in CSS Flexbox?</h3>
<p><code>center</code> aligns a flexible container's items to the center of the flexbox's main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-justify-content-center-illustration-codesweetly.png" alt="Illustration of justify-content's center value" width="600" height="400" loading="lazy">
<em>center aligns a flexible container's items to the center of the flexbox's main axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-jfzcwc?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>center</code> value to align the flexible container's items to the center of the flexbox.</p>
<h3 id="heading-what-is-justify-content-flex-end-in-css-flexbox">What is <code>justify-content: flex-end</code> in CSS Flexbox?</h3>
<p><code>flex-end</code> aligns a flexible container's items with the main-end side of the flexbox's main axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-justify-content-flex-end-illustration-codesweetly.png" alt="Illustration of justify-content's flex-end value" width="600" height="400" loading="lazy">
<em>flex-end aligns a flexible container's items with the main-end side of the flexbox's main axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: flex-end;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-iyhlbr?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-end</code> value to align the flexible container's items to the flexbox's main-end side.</p>
<h3 id="heading-what-is-justify-content-space-between-in-css-flexbox">What is <code>justify-content: space-between</code> in CSS Flexbox?</h3>
<p><code>space-between</code> does the following:</p>
<ul>
<li>It aligns a flexible container's first item with the main-start edge of the flexbox's main axis.</li>
<li>It aligns the container's last item with the main-end edge of the flexbox's main axis.</li>
<li>It creates even spacing between each pair of items between the first and last item.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-justify-content-space-between-illustration-codesweetly.png" alt="Illustration of justify-content's space-between value" width="600" height="400" loading="lazy">
<em>space-between creates even spacing between each pair of items between the first and last item.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-between;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-dylovp?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-between</code> value to create even spacing between each pair of items between the first and last flex item.</p>
<h3 id="heading-what-is-justify-content-space-around-in-css-flexbox">What is <code>justify-content: space-around</code> in CSS Flexbox?</h3>
<p><code>space-around</code> assigns equal spacing to each side of a flexible container's items.</p>
<p>Therefore, the space before the first item and after the last element is half the width of the space between each pair of elements.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-justify-content-space-around-illustration-codesweetly.png" alt="Illustration of justify-content's space-around value" width="600" height="400" loading="lazy">
<em>space-around assigns equal spacing to each side of a flexible container's items.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-around;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-t6wpcj?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-around</code> value to assign equal spacing to each side of the flexible container's items.</p>
<h3 id="heading-what-is-justify-content-space-evenly-in-css-flexbox">What is <code>justify-content: space-evenly</code> in CSS Flexbox?</h3>
<p><code>space-evenly</code> assigns even spacing to both ends of a flexible container and between its items.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-justify-content-space-evenly-illustration-codesweetly.png" alt="Illustration of justify-content's space-evenly value" width="600" height="400" loading="lazy">
<em>space-evenly assigns even spacing to both ends of a flexible container and between its items.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-evenly;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-p67eh8?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>space-evenly</code> value to assign even spacing to both ends of the flexbox and between its items.</p>
<p>Let's now discuss the fifth type of flexible container property.</p>
<h2 id="heading-what-is-flexboxs-align-items-property">What Is Flexbox's <code>align-items</code> Property?</h2>
<p><strong>align-items</strong> specifies how browsers should position a flexible container's items along the <a target="_blank" href="https://codesweetly.com/css-flex-direction-property#main-axis-vs-cross-axis-whats-the-difference">cross-axis</a> of the flexbox.</p>
<p>The <code>align-items</code> property accepts the following values:</p>
<ul>
<li><code>stretch</code></li>
<li><code>flex-start</code></li>
<li><code>center</code></li>
<li><code>flex-end</code></li>
<li><code>baseline</code></li>
</ul>
<p>Let's discuss the five values.</p>
<h3 id="heading-what-is-align-items-stretch-in-css-flexbox">What is <code>align-items: stretch</code> in CSS Flexbox?</h3>
<p><code>stretch</code> is <code>align-items</code>' default value. It stretches a flexible container's items to fill the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-items-stretch-illustration-codesweetly.png" alt="Illustration of align-items' stretch value" width="600" height="400" loading="lazy">
<em>stretch stretches a flexible container's items to fill the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: stretch;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ezugee?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch the flexible items to fill the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-items-flex-start-in-css-flexbox">What is <code>align-items: flex-start</code> in CSS Flexbox?</h3>
<p><code>flex-start</code> aligns a flexible container's items with the cross-start edge of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-items-flex-start-illustration-codesweetly.png" alt="Illustration of align-items' flex-start value" width="600" height="400" loading="lazy">
<em>flex-start aligns a flexible container's items with the cross-start edge of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: flex-start;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cjzhj2?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-start</code> value to align the flexible items to the cross-start edge of the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-items-center-in-css-flexbox">What is <code>align-items: center</code> in CSS Flexbox?</h3>
<p><code>center</code> aligns a flexible container's items to the center of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-items-center-illustration-codesweetly.png" alt="Illustration of align-items' center value" width="600" height="400" loading="lazy">
<em>center aligns a flexible container's items to the center of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ywexqr?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align the flexible items to the center of the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-items-flex-end-in-css-flexbox">What is <code>align-items: flex-end</code> in CSS Flexbox?</h3>
<p><code>flex-end</code> aligns a flexible container's items with the cross-end edge of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-items-flex-end-illustration-codesweetly.png" alt="Illustration of align-items' flex-end value" width="600" height="400" loading="lazy">
<em>flex-end aligns a flexible container's items with the cross-end edge of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: flex-end;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-bwdeyz?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-end</code> value to align the flexible items to the cross-end edge of the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-items-baseline-in-css-flexbox">What is <code>align-items: baseline</code> in CSS Flexbox?</h3>
<p><code>baseline</code> aligns a flexible container's items with the <a target="_blank" href="https://stackoverflow.com/a/34611670/11841906">baseline</a> of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-items-baseline-illustration-codesweetly.png" alt="Illustration of align-items' baseline value" width="600" height="400" loading="lazy">
<em>baseline aligns a flexible container's items with the baseline of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: baseline;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-xxvj57?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>baseline</code> value to align the flexible items to the <code>&lt;section&gt;</code>'s baseline.</p>
<p>Now, let's talk about the sixth CSS flexible container property type.</p>
<h2 id="heading-what-is-flexboxs-align-content-property">What Is Flexbox's <code>align-content</code> Property?</h2>
<p><strong>align-content</strong> specifies how browsers should position a flexible container's lines along the flexbox's <a target="_blank" href="https://codesweetly.com/css-flex-direction-property#main-axis-vs-cross-axis-whats-the-difference">cross-axis</a>.</p>
<p><strong>Note:</strong> The <code>align-content</code> property does not affect a flexbox with only one line—for instance, a flexible container with <code>flex-wrap: nowrap</code>. In other words, <code>align-content</code> works only on flexboxes with multiple lines.</p>
<p>The <code>align-content</code> property accepts the following values:</p>
<ul>
<li><code>stretch</code></li>
<li><code>flex-start</code></li>
<li><code>center</code></li>
<li><code>flex-end</code></li>
<li><code>space-between</code></li>
<li><code>space-around</code></li>
<li><code>space-evenly</code></li>
</ul>
<p>Let's discuss the seven values.</p>
<h3 id="heading-what-is-align-content-stretch-in-css-flexbox">What is <code>align-content: stretch</code> in CSS Flexbox?</h3>
<p><code>stretch</code> is <code>align-content</code>'s default value. It stretches the flexible container's lines to fill the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-content-stretch-illustration-codesweetly.png" alt="Illustration of align-content's stretch value" width="600" height="400" loading="lazy">
<em>stretch stretches the flexible container's lines to fill the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: stretch;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-dway6n?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch the flexbox's lines to fill the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-content-flex-start-in-css-flexbox">What is <code>align-content: flex-start</code> in CSS Flexbox?</h3>
<p><code>flex-start</code> aligns a flexible container's lines with the cross-start edge of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-content-flex-start-illustration-codesweetly.png" alt="Illustration of align-content's flex-start value" width="600" height="400" loading="lazy">
<em>flex-start aligns a flexible container's lines with the cross-start edge of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: flex-start;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-c9pzbc?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>flex-start</code> value to align the flexbox's lines to the cross-start edge of the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-content-center-in-css-flexbox">What is <code>align-content: center</code> in CSS Flexbox?</h3>
<p><code>center</code> aligns a flexible container's lines to the center of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-content-center-illustration-codesweetly.png" alt="Illustration of align-content's center value" width="600" height="400" loading="lazy">
<em>center aligns a flexible container's lines to the center of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: center;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-j3poyu?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>center</code> value to align the flexbox's lines to the center of the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-content-flex-end-in-css-flexbox">What is <code>align-content: flex-end</code> in CSS Flexbox?</h3>
<p><code>flex-end</code> aligns a flexible container's lines with the cross-end edge of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-content-flex-end-illustration-codesweetly.png" alt="Illustration of align-content's flex-end value" width="600" height="400" loading="lazy">
<em>flex-end aligns a flexible container's lines with the cross-end edge of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: flex-end;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cmaz6z?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-end</code> value to align the flexbox's lines to the cross-end edge of the <code>&lt;section&gt;</code>'s cross-axis.</p>
<h3 id="heading-what-is-align-content-space-between-in-css-flexbox">What is <code>align-content: space-between</code> in CSS Flexbox?</h3>
<p><code>space-between</code> does the following:</p>
<ul>
<li>It aligns the flexbox's first line with the main-start edge of the flexible container's main axis.</li>
<li>It aligns the flexbox's last line with the main-end side of the flexible container's main axis.</li>
<li>It creates equal spacing between each pair of lines between the first and last line.</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-content-space-between-illustration-codesweetly.png" alt="Illustration of align-content's space-between value" width="600" height="400" loading="lazy">
<em>space-between creates equal spacing between each pair of lines between the first and last line</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: space-between;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-kltdwx?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-between</code> value to create equal spacing between each pair of lines between the first and last line.</p>
<h3 id="heading-what-is-align-content-space-around-in-css-flexbox">What is <code>align-content: space-around</code> in CSS Flexbox?</h3>
<p><code>space-around</code> assigns equal spacing to each side of a flexible container's lines.</p>
<p>Therefore, the space before the first line and after the last one is half the width of the space between each pair of lines.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-content-space-around-illustration-codesweetly.png" alt="Illustration of align-content's space-around value" width="600" height="400" loading="lazy">
<em>space-around assigns equal spacing to each side of a flexible container's lines.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: space-around;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-kx9gdy?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>space-around</code> value to assign equal spacing to each side of the flexible container's lines.</p>
<h3 id="heading-what-is-align-content-space-evenly-in-css-flexbox">What is <code>align-content: space-evenly</code> in CSS Flexbox?</h3>
<p><code>space-evenly</code> assigns even spacing to both ends of a flexible container and between its lines.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-content-space-evenly-illustration-codesweetly.png" alt="Illustration of align-content's space-evenly value" width="600" height="400" loading="lazy">
<em>space-evenly assigns even spacing to both ends of a flexible container and between its lines.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">flex-wrap</span>: wrap;
  <span class="hljs-attribute">align-content</span>: space-evenly;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">90px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-eevqoj?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>space-evenly</code> value to assign even spacing to both ends of the flexbox and between its lines.</p>
<p>So, now that we know the types of CSS flexible container properties, we can discuss the flex item properties.</p>
<h2 id="heading-what-are-the-flexible-items-properties">What Are the Flexible Item's Properties?</h2>
<p>A flexible item's properties specify how browsers should layout a specified item within the flexible box model.</p>
<p><strong>Note:</strong> We define a flexible item's property on the flex item, not its container.</p>
<p>The six (6) types of flex item properties are:</p>
<ul>
<li><code>align-self</code></li>
<li><code>order</code></li>
<li><code>flex-grow</code></li>
<li><code>flex-shrink</code></li>
<li><code>flex-basis</code></li>
<li><code>flex</code></li>
</ul>
<p>Let's discuss the six types now.</p>
<h2 id="heading-what-is-flexboxs-align-self-property">What Is Flexbox's <code>align-self</code> Property?</h2>
<p><strong>align-self</strong> specifies how browsers should position selected flexible items along the flexbox's <a target="_blank" href="https://codesweetly.com/css-flex-direction-property#main-axis-vs-cross-axis-whats-the-difference">cross-axis</a>.</p>
<p><strong>Note:</strong></p>
<ul>
<li><code>align-self</code> affects only the selected flexible item—not all the flexbox's items.</li>
<li><code>align-self</code> overrides the <code>align-items</code> property.</li>
</ul>
<p>The <code>align-self</code> property accepts the following values:</p>
<ul>
<li><code>stretch</code></li>
<li><code>flex-start</code></li>
<li><code>center</code></li>
<li><code>flex-end</code></li>
<li><code>baseline</code></li>
</ul>
<p>Let's discuss the five values.</p>
<h3 id="heading-what-is-align-self-stretch-in-css-flexbox">What is <code>align-self: stretch</code> in CSS Flexbox?</h3>
<p><code>stretch</code> stretches the selected flexible items to fill the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-self-stretch-illustration-codesweetly.png" alt="Illustration of align-self's stretch value" width="600" height="400" loading="lazy">
<em>stretch stretches the selected flexible item(s) to fill the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item2</span> {
  <span class="hljs-attribute">align-self</span>: stretch;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-o5qr62?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>stretch</code> value to stretch <code>flex-item2</code> to fill its container's cross-axis.</p>
<h3 id="heading-what-is-align-self-flex-start-in-css-flexbox">What is <code>align-self: flex-start</code> in CSS Flexbox?</h3>
<p><code>flex-start</code> aligns the selected flexible items with the cross-start edge of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-self-flex-start-illustration-codesweetly.png" alt="Illustration of align-self's flex-start value" width="600" height="400" loading="lazy">
<em>flex-start aligns the selected flexible item(s) with the cross-start edge of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item2</span> {
  <span class="hljs-attribute">align-self</span>: flex-start;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-6uianm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>flex-start</code> value to align <code>flex-item2</code> to the cross-start edge of its container's cross-axis.</p>
<h3 id="heading-what-is-align-self-center-in-css-flexbox">What is <code>align-self: center</code> in CSS Flexbox?</h3>
<p><code>center</code> aligns the selected flexible items to the center of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-self-center-illustration-codesweetly.png" alt="Illustration of align-self's center value" width="600" height="400" loading="lazy">
<em>center aligns the selected flexible item(s) to the center of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item2</span> {
  <span class="hljs-attribute">align-self</span>: center;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-tazf2p?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align <code>flex-item2</code> to the center of its container's cross-axis.</p>
<h3 id="heading-what-is-align-self-flex-end-in-css-flexbox">What is <code>align-self: flex-end</code> in CSS Flexbox?</h3>
<p><code>flex-end</code> aligns the selected flexible items with the cross-end edge of the flexbox's cross-axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/css-align-self-flex-end-illustration-codesweetly.png" alt="Illustration of align-self's flex-end value" width="600" height="400" loading="lazy">
<em>flex-end aligns the selected flexible item(s) with the cross-end edge of the flexbox's cross-axis.</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item2</span> {
  <span class="hljs-attribute">align-self</span>: flex-end;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-7bec4q?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>flex-end</code> value to align <code>flex-item2</code> to the cross-end edge of its container's cross-axis.</p>
<h3 id="heading-what-is-align-self-baseline-in-css-flexbox">What is <code>align-self: baseline</code> in CSS Flexbox?</h3>
<p><code>baseline</code> aligns the selected flexible items with the <a target="_blank" href="https://stackoverflow.com/a/34611670/11841906">baseline</a> of the flexbox's cross-axis.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item2</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">3rem</span>;
  <span class="hljs-attribute">align-self</span>: baseline;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-wmawek?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>baseline</code> value to align <code>flex-item2</code> to its container's baseline.</p>
<p>Let's now discuss the second type of flexible item property.</p>
<h2 id="heading-what-is-flexboxs-order-property">What Is Flexbox's <code>order</code> Property?</h2>
<p><strong>order</strong> changes a flexible item's default order (arrangement).</p>
<p>In other words, <code>order</code> allows you to reposition a flexbox's item without altering your HTML code's layout.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"display: flex; flex-direction: column"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 6"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 4"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 1"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 7"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 2"</span>&gt;</span>5<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 5"</span>&gt;</span>6<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"order: 3"</span>&gt;</span>7<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-hmz9my?file=index.html"><strong>Try it on StackBlitz</strong></a></p>
<p>The HTML snippet above used the <code>order</code> property to change the unordered list's arrangement.</p>
<p>So, instead of the following order:</p>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
<p>The browser will display this:</p>
<ul>
<li>3</li>
<li>5</li>
<li>7</li>
<li>2</li>
<li>6</li>
<li>1</li>
<li>4</li>
</ul>
<p>Use the <code>order</code> property with caution, as it prevents screen readers from accessing the correct reading order of an HTML document. Only use it if it is super important to use CSS to change the HTML code's layout.</p>
<p>But in most cases, it is best to rearrange the HTML code directly rather than using CSS.</p>
<p><strong>Note:</strong> The <code>style="value"</code> syntax, in the HTML snippet above, is the <a target="_blank" href="https://codesweetly.com/inline-vs-internal-vs-external-css#what-is-an-inline-css">inline CSS</a> technique for styling HTML elements.</p>
<h2 id="heading-what-is-flexboxs-flex-grow-property">What Is Flexbox's <code>flex-grow</code> Property?</h2>
<p><strong>flex-grow</strong> tells browsers how much of the flexbox's left-over space they should add to the selected flexible item's size.</p>
<p><strong>Note:</strong> A left-over space refers to the space remaining after browsers have deducted the sum of all flexible items' sizes from the flexbox's size.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item3</span> {
  <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">0.5</span>;
}
</code></pre>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item1"</span>&gt;</span>1<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item2"</span>&gt;</span>2<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item3"</span>&gt;</span>3<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-item4"</span>&gt;</span>4<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-grtdo1?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-grow</code> property to make browsers add half of <code>&lt;section&gt;</code>'s left-over space to <code>flex-item3</code>'s size.</p>
<p><strong>Note:</strong> <code>flex-grow</code>'s default value is <code>0</code>.</p>
<h2 id="heading-what-is-flexboxs-flex-shrink-property">What Is Flexbox's <code>flex-shrink</code> Property?</h2>
<p><strong>flex-shrink</strong> tells browsers how much the specified flexible item should shrink when the sum of all items' sizes exceeds the flexbox's size.</p>
<p>In other words, suppose the flexbox's size is insufficient to fit the flexible items. In that case, browsers will shrink the items to fit the container.</p>
<p>Therefore, <code>flex-shrink</code> allows you to specify the shrinking factor of a flexible item.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item3</span> {
  <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">0</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-h2numw?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-shrink</code> property to prevent browsers from shrinking <code>flex-item3</code>.</p>
<p><strong>Note:</strong></p>
<ul>
<li>Browsers will not shrink flexible items with a <code>flex-shrink</code> value of <code>0</code>.</li>
<li><code>flex-shrink</code>'s default value is <code>1</code>.</li>
</ul>
<h2 id="heading-what-is-flexboxs-flex-basis-property">What Is Flexbox's <code>flex-basis</code> Property?</h2>
<p><strong>flex-basis</strong> sets the initial length of a flexible item.</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item3</span> {
  <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-kwcche?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the <code>flex-basis</code> property to set <code>flex-item3</code>'s initial length to <code>100px</code>.</p>
<p><strong>Note the following:</strong></p>
<ul>
<li><code>auto</code> is <code>flex-basis</code>' default value.</li>
<li>A <code>flex-basis</code>' value (other than <code>auto</code>) has higher specificity than <code>width</code> (or <code>height</code>). Therefore, suppose you define both for a flexible item. In that case, browsers will use <code>flex-basis</code>.</li>
<li>The <code>flex-basis</code> property sets the <a target="_blank" href="https://codesweetly.com/css-box-model#what-is-a-content-box">content box</a>'s initial width. But you can use the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing">box-sizing</a> property to make it set the <a target="_blank" href="https://codesweetly.com/css-box-model#what-is-a-border-box">border box</a>'s width instead.</li>
</ul>
<h2 id="heading-what-is-flexboxs-flex-property">What Is Flexbox's <code>flex</code> Property?</h2>
<p><strong>flex</strong> is a shorthand for the <code>flex-grow</code>, <code>flex-shrink</code>, and <code>flex-basis</code> properties.</p>
<p>In other words, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item3</span> {
  <span class="hljs-attribute">flex-grow</span>: <span class="hljs-number">0.5</span>;
  <span class="hljs-attribute">flex-shrink</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">flex-basis</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p>You can alternatively use the <code>flex</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.flex-item3</span> {
  <span class="hljs-attribute">flex</span>: <span class="hljs-number">0.5</span> <span class="hljs-number">0</span> <span class="hljs-number">100px</span>;
}
</code></pre>
<p><strong>Note the following:</strong></p>
<ul>
<li><code>flex: auto</code> is equivalent to <code>flex: 1 1 auto</code>.</li>
<li><code>flex: none</code> is equivalent to <code>flex: 0 0 auto</code>.</li>
<li><code>flex: initial</code> sets the <code>flex</code> property to its default value. It is equivalent to <code>flex: 0 1 auto</code>.</li>
<li><code>flex: inherit</code> inherits its parent element's <code>flex</code> property's values.</li>
</ul>
<p>So, now that we know the flexbox properties developers use to layout flexible boxes and their direct children, we can discuss how to center elements with flexbox.</p>
<h2 id="heading-how-to-center-elements-horizontally-with-flexbox">How to Center Elements Horizontally with Flexbox</h2>
<p>You can center any element horizontally within its container by:</p>
<ul>
<li>Setting its container's <code>display</code> property to <code>flex</code></li>
<li>Setting the flexible container's <code>justify-content</code> property to <code>center</code></li>
</ul>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-trl46e?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<h2 id="heading-how-to-center-elements-vertically-with-flexbox">How to Center Elements Vertically with Flexbox</h2>
<p>You can center any element vertically within its container by:</p>
<ul>
<li>Setting its container's <code>display</code> property to <code>flex</code></li>
<li>Setting the flexible container's <code>align-items</code> property to <code>center</code></li>
</ul>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-tm1don?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<h2 id="heading-how-to-center-elements-horizontally-and-vertically-with-flexbox">How to Center Elements Horizontally and Vertically with Flexbox</h2>
<p>You can center any HTML element horizontally and vertically within its container by:</p>
<ul>
<li>Setting its container's <code>display</code> property to <code>flex</code></li>
<li>Setting the flexible container's <code>justify-content</code> and <code>align-items</code> properties to <code>center</code></li>
</ul>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ryzwmq?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<h2 id="heading-overview">Overview</h2>
<p>In this article, we discussed all the Flexbox tools you need to create basic and advanced website layouts in flexible and responsive ways.</p>
<h3 id="heading-thanks-for-reading">Thanks for reading!</h3>
<p>If you like the images I used in this tutorial, you can get them all in <a target="_blank" href="https://store.codesweetly.com/l/css-flexbox-explained-visually">this booklet</a>.</p>
<h3 id="heading-and-heres-a-useful-reactjs-resource">And here's a useful ReactJS resource:</h3>
<p>I wrote a book about React!</p>
<ul>
<li>It's beginner friendly ✔</li>
<li>It has live code snippets ✔</li>
<li>It contains scalable projects ✔</li>
<li>It has plenty of easy-to-grasp examples ✔</li>
</ul>
<p>The <a target="_blank" href="https://www.amazon.com/dp/B09KYGDQYW">React Explained Clearly</a> book is all you need to understand ReactJS.</p>
<p><a target="_blank" href="https://www.amazon.com/dp/B09KYGDQYW"><img src="https://www.freecodecamp.org/news/content/images/2022/01/Twitter-React_Explained_Clearly-CodeSweetly-Oluwatobi_Sofela.jpg" alt="React Explained Clearly Book Now Available at Amazon" width="600" height="400" loading="lazy"></a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Web Layouts – How to Use CSS Grid and Flex to Create a Responsive Web Page ]]>
                </title>
                <description>
                    <![CDATA[ Your web layout is to your website what a floor plan is to a building. Without them, you’re just building castles in the air.  The first thing to do when you have a website or application to build or design is to decide on the layout. This is importa... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/web-layouts-use-css-grid-and-flex-to-create-responsive-webpages/</link>
                <guid isPermaLink="false">66c5a349dd1f1e4092a32568</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ophy Boamah ]]>
                </dc:creator>
                <pubDate>Fri, 21 Oct 2022 23:12:52 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/WebLayouts-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Your web layout is to your website what a floor plan is to a building. Without them, you’re just building castles in the air. </p>
<p>The first thing to do when you have a website or application to build or design is to decide on the layout. This is important because it is within this layout that you specify how elements are arranged so that you can assess them in their intended manner and hierarchy.</p>
<p>Basically, the aim of every web layout is to reduce confusion, enhance usability and to ultimately give your users an enjoyable experience. Some of the main elements of a layout are navigation, menus and content. </p>
<p>In web and front-end development, having a layout in mind ahead of building can help you decide on what CSS layout module to use: Flexbox or Grid.</p>
<p>In this article, we’re going to learn what each of these tools are and the best way to use them by building a simple yet beautiful landing page.</p>
<h2 id="heading-what-were-going-to-build">What We're Going To Build</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/homepage-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>landing page design</em></p>
<p>Check it out on Codepen <a target="_blank" href="https://codepen.io/ophyboamah/pen/KKRLoJr">here</a>.</p>
<h2 id="heading-project-functionality">Project Functionality</h2>
<ol>
<li>Web Layout: Create a beautiful landing page</li>
<li>Mobile Responsiveness</li>
</ol>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li>Basic knowledge of HTML and CSS.</li>
<li>An IDE (text editor) like VS Code</li>
<li>A web browser</li>
</ul>
<h2 id="heading-setup">Setup</h2>
<ol>
<li>Create a folder for your project and open in an IDE.</li>
<li>Within your project folder, create index.html and style.css files.</li>
<li>Create an asset folder to store images.</li>
<li>Within your index.html file, create your HTML boilerplate and link your CSS file and font URL within the <code>&lt;head&gt;</code> tag.</li>
</ol>
<h2 id="heading-resources">Resources</h2>
<ol>
<li><strong>Font:</strong> <a target="_blank" href="https://fonts.googleapis.com/css2?family=Epilogue:wght@500;700&amp;family=Poppins:wght@400;500;700&amp;display=swap">https://fonts.googleapis.com/css2?family=Epilogue:wght@500;700&amp;family=Poppins:wght@400;500;700&amp;display=swap</a></li>
<li><strong>Desktop Image:</strong> <a target="_blank" href="https://i.postimg.cc/0Nt97Bhf/image-hero-desktop.png">https://i.postimg.cc/0Nt97Bhf/image-hero-desktop.png</a></li>
<li><strong>Mobile Image:</strong> <a target="_blank" href="https://i.postimg.cc/ZnYfhwwW/image-hero-mobile.png">https://i.postimg.cc/ZnYfhwwW/image-hero-mobile.png</a></li>
<li><strong>Client Logo (Databiz):</strong> <a target="_blank" href="https://i.postimg.cc/gJ9Y84m6/client-databiz.png">https://i.postimg.cc/gJ9Y84m6/client-databiz.png</a></li>
<li><strong>Client Logo (Audiophile):</strong> <a target="_blank" href="https://i.postimg.cc/15DDqYSD/client-audiophile.png">https://i.postimg.cc/15DDqYSD/client-audiophile.png</a></li>
<li><strong>Client Logo (Meet):</strong> <a target="_blank" href="https://i.postimg.cc/5ybQqfbv/client-meet.png">https://i.postimg.cc/5ybQqfbv/client-meet.png</a></li>
<li><strong>Client Logo (Maker):</strong> <a target="_blank" href="https://i.postimg.cc/g2NsxByN/client-maker.png">https://i.postimg.cc/g2NsxByN/client-maker.png</a></li>
</ol>
<h1 id="heading-how-to-use-flexbox">How to Use Flexbox</h1>
<p>Generally, HTML elements align according to their default display style. This means, without external styling with CSS, block elements like <code>p</code> and <code>div</code> will start on a new line. Inline elements like <code>input</code> and <code>span</code>, on the other hand, are arranged next to each other on the same line.</p>
<p>However, the concept of Flexbox allows you to easily place these elements either horizontally or vertically in what’s often referred to as one dimension. In order to achieve this, at least two elements are required: <strong>flex container</strong> and <strong>flex item</strong>. These refer to a parent and child element, respectively.</p>
<p>In responsive design, the purpose of Flexbox is to allow containers and their child elements to fill defined spaces or shrink depending on a device’s dimensions.</p>
<h2 id="heading-flex-direction-and-axes">Flex-direction and Axes</h2>
<p>Flex-direction is an important property of CSS Flexbox, because it is what determines the direction that flex items are arranged in. It does this by pointing out the main axis of a flex container.</p>
<p>There are two main axes, namely <strong>main axis</strong> and <strong>cross axis</strong>. The main axis is the defined direction of how your flex items are placed in the flex container, whilst the cross axis is always the axis at the opposite side of the main axis. </p>
<p>It can be dangerous to try using the concept of x and y axis from math to understand this. This is mainly because in Flexbox the main axis can be vertical or horizontal, always depending on the value of the flex-direction.</p>
<p>The values accepted by the flex-direction property include row (which is default), row-reverse, column, and column-reverse. For the purposes of this project, we’re going to look at row and column.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/flexdirection.png" alt="Image" width="600" height="400" loading="lazy">
<em>flex-direction: row</em></p>
<p>When the flex-direction attribute has a value of row, the main axis is horizontal and the cross axis is vertical, as shown in the image above. This means flex items will be arranged horizontally. </p>
<p>Since the row is the default value, if you display a container as flex but don't specify the flex-direction, the flex items will automatically be in a row.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/flexdirectioncolumn.png" alt="Image" width="600" height="400" loading="lazy">
<em>flex-direction: column</em></p>
<p>When the flex-direction attribute has a value of column, the main axis is vertical and the cross axis is horizontal, as shown in the image above. This means flex items will be arranged vertically. </p>
<h2 id="heading-how-to-build-the-navbar">How to Build the Navbar</h2>
<p>Now that we know how Flexbox works, let’s start building our navbar. We'll first provide the content within it, that is the menu items and logo. We’ll give them descriptive classes so that we can easily reference them within our CSS file.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"logo"</span>&gt;</span>snap<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu-items"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Features<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Company<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Careers<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cta-btns"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Register<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
<p>The image below is the output for the code above. Because both <code>&lt;ul&gt;</code> and <code>&lt;li&gt;</code>  are block elements, each of the items we specified within them will be displayed on a new line.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/preflexx-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Navbar content output</em></p>
<p>Flexbox layout display is declared on parent containers and affects child elements. This means that if you had a list of groceries in an unordered list, display flex can’t be applied on the <code>&lt;li&gt;</code>s which are child elements in this case. Instead, to display them as flex, you’d first have to create a parent container and apply it to that. </p>
<p>In our CSS code below, we're defining the font style and size for our project as well as our navbar logo. We're also displaying our nav elements and some of the elements within those as flex. </p>
<pre><code class="lang-css">* {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">"Epilogue"</span>, sans-serif;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.85rem</span>;
}

<span class="hljs-selector-class">.logo</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.3rem</span>;
}

<span class="hljs-selector-tag">nav</span>,
<span class="hljs-selector-class">.cta-btns</span>,
<span class="hljs-selector-class">.menu-items</span> {
  <span class="hljs-attribute">display</span>: flex;
}
</code></pre>
<p>The image below is the output for the code above. The elements have been displayed as flex. Yet because we didn't specify the flex-direction, they're automatically arranged in a row. </p>
<p>But as you can see below using the ruler (red line), the flex items are not aligned as they should be. Let's fix that by learning another important flex element.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/displayflex.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flex without alignment</em></p>
<h3 id="heading-how-to-use-the-align-items-attribute">How to use the <code>align-items</code> attribute</h3>
<p>This is a Flexbox attribute that controls the arrangement of flex items on the cross axis. The values it takes are flex-start, flex-end and center depending on the element's alignment needs. The image below shows how each of them works. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/align-items-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Image credit: freeCodeCamp</em></p>
<p>From the image above, we can see that if we want to ensure that the flex items within our <code>&lt;nav&gt;</code> are aligned properly, on that element we must give the align-items attribute a value of center. So we have to add an attribute of <em>align-items</em> and a value of <em>center</em> to our flex container as shown in the CSS code below:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">nav</span>,
<span class="hljs-selector-class">.cta-btns</span>,
<span class="hljs-selector-class">.menu-items</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<p>As you can see in the image below, the flex items are now aligned as they should be. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/aligncenter.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flex with center alignment</em></p>
<p>But once again there is something missing. We want to have our items spread out properly on the navbar: the logo on the extreme left, login and register at the extreme right, and the rest in the middle. </p>
<p>We can achieve this with the <code>justify-content</code> attribute. Let's learn about it next and then implement it.</p>
<h3 id="heading-how-to-use-the-justify-content-attribute">How to use the <code>justify-content</code> attribute</h3>
<p>This is a Flexbox attribute that controls the arrangement of flex items on the main axis. It also defines how browsers distribute space between and around flex items within a flex container. </p>
<p>To achieve responsiveness, it helps with allocating any excess space that is leftover after flex-items have been arranged.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/justifycontentstyles.png" alt="Image" width="600" height="400" loading="lazy">
<em>justify-content styles</em></p>
<p>From the styles associated with the various values of the justify-content attribute, we can see that the bottom two are more similar to what we're trying to achieve. </p>
<p>We can either go for the space around or the space-between and provide some padding on the sides to push the items on the extreme ends from the edges. We also give the list-syle attribute a value of none to remove the dots in front of the list items.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">list-style</span>: none;
}

<span class="hljs-selector-tag">nav</span> {
  <span class="hljs-attribute">justify-content</span>: space-between;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/justifycontent-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>justify-content navbar output</em></p>
<p>Now that we have the items placed at their desired positions, we need to create slight spaces between them. In this case, we're going to give each list item a margin-right of 1rem. We also set other styles like size of fonts, color and a border for the register item. </p>
<pre><code class="lang-css"><span class="hljs-selector-tag">nav</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">1.5rem</span> <span class="hljs-number">1.5rem</span> <span class="hljs-number">1.5rem</span>;
  <span class="hljs-attribute">justify-content</span>: space-between;
}

<span class="hljs-selector-class">.logos-section</span> {
  <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-class">.menu-items</span> <span class="hljs-selector-tag">li</span>,
<span class="hljs-selector-class">.cta-btns</span> <span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0%</span>, <span class="hljs-number">41%</span>);
}

<span class="hljs-selector-class">.cta-btns</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:nth-last-child(1)</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid gray;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.2rem</span> <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0.3rem</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/justifyandstyles-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Navbar with styles</em></p>
<p>After implementing the above code, this is the final look of our navbar. And this marks the end of our Flexbox section. Next, we'll build the final part of our landing page with CSS Grid.</p>
<h1 id="heading-how-to-use-css-grid">How to Use CSS Grid</h1>
<p>CSS Grid is a life-changing tool for creating web layouts. It helps you make both simple and complex layouts. The main difference is that while Flexbox helps with one dimensional arrangement of elements, CSS grid is able to do two dimensional arrangements. </p>
<p>The concept of axes we learnt about under Flexbox still applies here. You can use CSS Grid to arrange elements on the main axis and cross axis at the same time. </p>
<p>In summary, Flexbox, allows you to either arrange elements horizontally (in a row) or vertically (in a column). But with CSS Grid you can align elements both vertically and horizontally.</p>
<p>The CSS Grid layout is declared only on parent elements or containers. In effect, all its children become grid items. Once you have the target container, you give it an attribute of display and value of grid. The size of a grid’s row and column can be determined with <code>grid-template-rows</code> and <code>grid-template-columns</code>, respectively.</p>
<h2 id="heading-how-to-build-the-homepage">How to Build the Homepage</h2>
<p>Just like we did with the navbar, let's start by defining our content within a <code>&lt;main&gt;</code> section in our HTML file. </p>
<p>Looking at our target image, we have two main sections: the left section will have text and logos whilst the right section has a hero image. That’s for the web view of our project. </p>
<p>Let's start by defining our content. The section with class text-side contains: heading, paragraph text, button and logo. The section with class img-side only contains an image.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"text-side"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Make <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>remote work<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
          Get your team in sync, no matter your location. Streamline processes,
          create team rituals, and watch productivity soar.
        <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Learn more<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"clients-logos"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/images/client-databiz.svg"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/images/client-audiophile.svg"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/images/client-meet.svg"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/images/client-maker.svg"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"img-side"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./assets/images/image-hero-desktop.png"</span> /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
<p>Within the main section, we created the two sections we needed and gave them descriptive id's: text-side and img-side. </p>
<p>Within the text-side, we added a heading, paragraph text, button and a div to display clients' logos. The only thing we need for the img-side is the display image.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Client Logos */</span>
<span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">5rem</span>;
  <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">1rem</span>;
}

<span class="hljs-selector-class">.clients-logos</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">4rem</span>;
}

<span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-pseudo">:nth-child(2)</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">3rem</span>;
}

<span class="hljs-comment">/* Main */</span>
<span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">3rem</span>;
}

<span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">18rem</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0%</span>, <span class="hljs-number">41%</span>);
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0.9rem</span>;
}

<span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0%</span>, <span class="hljs-number">8%</span>);
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.6rem</span> <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0.4rem</span>;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">1rem</span>;
}

<span class="hljs-selector-id">#text-side</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">3rem</span>;
}
<span class="hljs-comment">/* Hero Image */</span>
<span class="hljs-selector-class">.img-side</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">20rem</span>;
}
</code></pre>
<p>Within our CSS file, we need to style the client logos div as well as the child elements. We also set a font-size for the heading and paragraph. Next, we style our button and assign a width to our image.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/pregrid1-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>pre-grid homepage display</em></p>
<p>The image above shows how our web page will look after defining the content and styling just the heading, button and logos – that is, we haven't declared our container as a grid yet. Because almost all the elements we have here are block elements, we see them align on top of one another.</p>
<h2 id="heading-grid-template-rows-and-columns">Grid Template Rows and Columns</h2>
<p>The <code>grid-template-columns</code> property specifies the number and widths of columns in a grid, defining a grid container's column by specifying the size of its tracks and line names. </p>
<p>The <code>grid-template-rows</code> property is the direct opposite. It specifies the number and heights of rows in a grid, also defining a grid container's row by specifying the size of its tracks and line names. </p>
<p>As you can see in the image below, <code>grid-template-rows</code> arranges elements from the top to bottom of the device screen. <code>grid-template-columns</code> arranges elements from the left to right side of the device screen. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/CSS-Grid.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>For our project, we're going to make use of <code>grid-template-columns</code> since we want to arrange our two sections side by side, letting each section occupy an equal part of the overall project width. We do this by assigning it as an attribute on the same container that we specified a display of grid on. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/displaygrid.png" alt="Image" width="600" height="400" loading="lazy">
<em>display: grid</em></p>
<p>Now that the two sections inside our <code>&lt;main&gt;</code> tag have been placed equally using the grid-template-columns, we have two last things to do. </p>
<p>We need to align them horizontally, by positioning both elements in the center of the page, with the extra space on the left of the image, evenly distributed on both sides. We also need to align them vertically by positioning both of them in the center of the page, with the extra space on the bottom, evenly distributed above and beneath.</p>
<h2 id="heading-align-and-justify-in-css-grid">Align and Justify in CSS Grid</h2>
<p>Good news – we don't have to learn any new concepts to achieve our desired alignments in CSS Grid Layouts. Because fortunately, <code>align-items</code> and <code>justify-content</code>, as we learnt earlier, are not exclusive to Flebox. You can also use them to position items both horizontally and vertically.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">main</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">height</span>: <span class="hljs-number">70vh</span>;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">8rem</span>;
}
</code></pre>
<p>As you can see in the code above, we only had to give the value of center to both align-items and justify-content attributes on the parent tag (grid container). </p>
<p>To ensure that we see the effect of position in the perfect center, we also had to specify a height for the section. The image below is the final output of our project.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/homepage-4.png" alt="Image" width="600" height="400" loading="lazy">
<em>Landing page final look</em></p>
<h2 id="heading-how-to-make-it-responsive">How to Make it Responsive</h2>
<p>So far, everything we've built is for the web. But for the sake of users who want to access the landing page on mobile, we have to make our project accessible on smaller screens. In our case, we're looking at screens that are greater than 300px but less than 480px. </p>
<p>As you can see in the code below, we're hiding our nav items and displaying an emoji with class of mobile-nav. Beside that, we're hiding the desktop header image and showing the mobile header image. </p>
<pre><code class="lang-css"><span class="hljs-comment">/* Responsive */</span>
<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">300px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">480px</span>) {
  * {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1rem</span>;
  }

  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100vw</span>;
    <span class="hljs-attribute">overflow-y</span>: hidden;
    <span class="hljs-attribute">overflow-x</span>: hidden;
  }

  <span class="hljs-selector-tag">nav</span> {
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">1.5rem</span> <span class="hljs-number">0</span> <span class="hljs-number">1.5rem</span>;
  }

  <span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">display</span>: none;
  }

  <span class="hljs-selector-class">.mobile-nav</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">2rem</span>;
  }

  <span class="hljs-selector-tag">main</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
  }

  <span class="hljs-comment">/* Clients logos */</span>
  <span class="hljs-selector-class">.clients-logos</span> {
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">2rem</span>;
  }

  <span class="hljs-selector-class">.desktop-logos</span> {
    <span class="hljs-attribute">display</span>: none;
  }

  <span class="hljs-selector-class">.mobile-logos</span> {
    <span class="hljs-attribute">display</span>: block;
  }

  <span class="hljs-comment">/* Images */</span>
  <span class="hljs-selector-class">.desktop-img</span> {
    <span class="hljs-attribute">display</span>: none;
  }
  <span class="hljs-selector-class">.mobile-img</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">3rem</span>;
  }

  <span class="hljs-selector-class">.cta-btns</span>,
  <span class="hljs-selector-class">.menu-items</span> {
    <span class="hljs-attribute">display</span>: none;
  }

  <span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">h1</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2.5rem</span>;
  }

  <span class="hljs-comment">/* Client Logos */</span>
  <span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">4.5rem</span>;
    <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">0.8rem</span>;
  }

  <span class="hljs-selector-class">.attribution</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">13rem</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">8rem</span> auto <span class="hljs-number">0</span> auto;
    <span class="hljs-attribute">text-align</span>: center;
  }
}
</code></pre>
<h2 id="heading-full-project-code">Full Project Code</h2>
<p>This is the project we’ve built together in this article:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/homepage-3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here's the full HTML code:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span> /&gt;</span>
    <span class="hljs-comment">&lt;!-- displays site properly based on user's device --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"preconnect"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"preconnect"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.gstatic.com"</span> <span class="hljs-attr">crossorigin</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
      <span class="hljs-attr">href</span>=<span class="hljs-string">"https://fonts.googleapis.com/css2?family=Epilogue:wght@500;700&amp;family=Poppins:wght@400;500;700&amp;display=swap"</span>
      <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span>
    /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span>
      <span class="hljs-attr">rel</span>=<span class="hljs-string">"icon"</span>
      <span class="hljs-attr">type</span>=<span class="hljs-string">"image/png"</span>
      <span class="hljs-attr">sizes</span>=<span class="hljs-string">"32x32"</span>
      <span class="hljs-attr">href</span>=<span class="hljs-string">"./images/favicon-32x32.png"</span>
    /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Web Layout | Landing Page<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- Feel free to remove these styles or customise in your own stylesheet 👍 --&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"logos-section"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"logo"</span>&gt;</span>snap<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu-items"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
            Features<span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
              <span class="hljs-attr">width</span>=<span class="hljs-string">"10"</span>
              <span class="hljs-attr">height</span>=<span class="hljs-string">"6"</span>
              <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
            &gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">path</span>
                <span class="hljs-attr">stroke</span>=<span class="hljs-string">"#686868"</span>
                <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">"1.5"</span>
                <span class="hljs-attr">fill</span>=<span class="hljs-string">"none"</span>
                <span class="hljs-attr">d</span>=<span class="hljs-string">"m1 1 4 4 4-4"</span>
              /&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>
            Company<span class="hljs-tag">&lt;<span class="hljs-name">svg</span>
              <span class="hljs-attr">width</span>=<span class="hljs-string">"10"</span>
              <span class="hljs-attr">height</span>=<span class="hljs-string">"6"</span>
              <span class="hljs-attr">xmlns</span>=<span class="hljs-string">"http://www.w3.org/2000/svg"</span>
            &gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">path</span>
                <span class="hljs-attr">stroke</span>=<span class="hljs-string">"#686868"</span>
                <span class="hljs-attr">stroke-width</span>=<span class="hljs-string">"1.5"</span>
                <span class="hljs-attr">fill</span>=<span class="hljs-string">"none"</span>
                <span class="hljs-attr">d</span>=<span class="hljs-string">"m1 1 4 4 4-4"</span>
              /&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">svg</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Careers<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cta-btns"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Login<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Register<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"mobile-nav"</span>&gt;</span>🌚<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"text-side"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Make <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>remote work<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
          Get your team in sync, no matter your location. Streamline processes,
          create team rituals, and watch productivity soar.
        <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span>&gt;</span>Learn more<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"clients-logos"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.postimg.cc/gJ9Y84m6/client-databiz.png"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.postimg.cc/15DDqYSD/client-audiophile.png"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.postimg.cc/5ybQqfbv/client-meet.png"</span> /&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.postimg.cc/g2NsxByN/client-maker.png"</span> /&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"img-side"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span>
          <span class="hljs-attr">class</span>=<span class="hljs-string">"desktop-img"</span>
          <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.postimg.cc/0Nt97Bhf/image-hero-desktop.png"</span>
        /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">img</span>
          <span class="hljs-attr">class</span>=<span class="hljs-string">"mobile-img"</span>
          <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i.postimg.cc/ZnYfhwwW/image-hero-mobile.png"</span>
        /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"attribution"</span>&gt;</span>
      Challenge by
      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://www.frontendmentor.io?ref=challenge"</span> <span class="hljs-attr">target</span>=<span class="hljs-string">"_blank"</span>
        &gt;</span>Frontend Mentor<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>
      &gt;</span>. Coded by <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://codehemaa.com"</span>&gt;</span>Ophy Boamah<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>.
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>Here's the full CSS code:</p>
<pre><code class="lang-css">* {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">"Epilogue"</span>, sans-serif;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.3rem</span>;
}

<span class="hljs-selector-class">.logo</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1.3rem</span>;
}

<span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">list-style</span>: none;
}

<span class="hljs-selector-tag">nav</span>,
<span class="hljs-selector-class">.cta-btns</span>,
<span class="hljs-selector-class">.menu-items</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-selector-tag">nav</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">1.5rem</span> <span class="hljs-number">1.5rem</span> <span class="hljs-number">1.5rem</span>;
  <span class="hljs-attribute">justify-content</span>: space-between;
}

<span class="hljs-selector-class">.mobile-nav</span> {
    <span class="hljs-attribute">display</span>: none;
}

<span class="hljs-selector-class">.logos-section</span> {
  <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-class">.menu-items</span> <span class="hljs-selector-tag">li</span>,
<span class="hljs-selector-class">.cta-btns</span> <span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0%</span>, <span class="hljs-number">41%</span>);
}

<span class="hljs-selector-class">.cta-btns</span> <span class="hljs-selector-tag">li</span><span class="hljs-selector-pseudo">:nth-last-child(1)</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid gray;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.2rem</span> <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0.3rem</span>;
}

<span class="hljs-comment">/* Client Logos */</span>

<span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">8rem</span>;
  <span class="hljs-attribute">margin-right</span>: -<span class="hljs-number">3rem</span>;
}

<span class="hljs-selector-class">.clients-logos</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">margin-left</span>: -<span class="hljs-number">2rem</span>;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">10rem</span>;
}

<span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-pseudo">:nth-child(2)</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">7rem</span>;
}

<span class="hljs-comment">/* Main */</span>
<span class="hljs-selector-tag">main</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">height</span>: <span class="hljs-number">70vh</span>;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">8rem</span>;
}
<span class="hljs-comment">/* Images */</span>
<span class="hljs-selector-class">.desktop-img</span> {
  <span class="hljs-attribute">display</span>: block;
}
<span class="hljs-selector-class">.mobile-img</span> {
  <span class="hljs-attribute">display</span>: none;
}

<span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">3rem</span>;
}

<span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">18rem</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0%</span>, <span class="hljs-number">41%</span>);
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">0.9rem</span>;
}

<span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">button</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0%</span>, <span class="hljs-number">8%</span>);
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0.6rem</span> <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">0.4rem</span>;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">1rem</span>;
}

<span class="hljs-selector-id">#text-side</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">3rem</span>;
}
<span class="hljs-comment">/* Hero Image */</span>
<span class="hljs-selector-id">#img-side</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">20rem</span>;
}

<span class="hljs-selector-class">.attribution</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">5.5rem</span>;
}

<span class="hljs-selector-class">.attribution</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">228</span>, <span class="hljs-number">45%</span>, <span class="hljs-number">44%</span>);
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">0.7rem</span>;
}

<span class="hljs-comment">/* Responsive */</span>
<span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">300px</span>) <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">480px</span>) {
  * {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">1rem</span>;
  }

  <span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100vw</span>;
    <span class="hljs-attribute">overflow-y</span>: hidden;
    <span class="hljs-attribute">overflow-x</span>: hidden;
  }

  <span class="hljs-selector-tag">nav</span> {
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">1.5rem</span> <span class="hljs-number">0</span> <span class="hljs-number">1.5rem</span>;
  }

  <span class="hljs-selector-tag">nav</span> <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">display</span>: none;
  }

  <span class="hljs-selector-class">.mobile-nav</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">2rem</span>;
  }

  <span class="hljs-selector-tag">main</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">margin</span>: -<span class="hljs-number">3rem</span> auto <span class="hljs-number">0</span> auto;
  }

  <span class="hljs-comment">/* Clients logos */</span>
  <span class="hljs-selector-class">.clients-logos</span> {
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">2rem</span>;
  }

  <span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">30rem</span>;
}

<span class="hljs-selector-class">.clients-logos</span> {
  <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">1rem</span>;
  <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span><span class="hljs-selector-pseudo">:nth-child(2)</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">7rem</span>;
}

  <span class="hljs-comment">/* Images */</span>
  <span class="hljs-selector-class">.desktop-img</span> {
    <span class="hljs-attribute">display</span>: none;
  }
  <span class="hljs-selector-class">.mobile-img</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">margin-top</span>: <span class="hljs-number">3rem</span>;
  }

  <span class="hljs-selector-class">.cta-btns</span>,
  <span class="hljs-selector-class">.menu-items</span> {
    <span class="hljs-attribute">display</span>: none;
  }

  <span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">h1</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2.5rem</span>;
  }

  <span class="hljs-comment">/* Client Logos */</span>
  <span class="hljs-selector-class">.clients-logos</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">4.5rem</span>;
    <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">0.8rem</span>;
  }

  <span class="hljs-selector-class">.attribution</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">13rem</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">10rem</span> auto <span class="hljs-number">0</span> auto;
    <span class="hljs-attribute">text-align</span>: center;
  }
}
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>As a web developer, layouts should be the first thing you consider before writing code. Thankfully, CSS Grid and Flexbox have revolutionized the way we structure and build website and web app layouts. </p>
<p>This makes these concepts a must know so you can specify the arrangement of elements on the web. We've discussed the fundamentals, so that you can easily build up on the knowledge and create beautiful web pages and apps. </p>
<p>Thanks for reading 👋🏾. I hope you found this helpful.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Image Centering – How to Center an Image in a Div ]]>
                </title>
                <description>
                    <![CDATA[ When you're working on the front-end of a web page, you sometimes need to center an image within a div (container). This can become tricky at times. And based on certain conditions, a particular method may not work at some point, leaving you searchin... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-center-an-image-in-a-div-css/</link>
                <guid isPermaLink="false">66d45f8836c45a88f96b7cf7</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ css flex ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joel Olawanle ]]>
                </dc:creator>
                <pubDate>Tue, 16 Aug 2022 19:32:10 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/cover-template.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When you're working on the front-end of a web page, you sometimes need to center an image within a <code>div</code> (container).</p>
<p>This can become tricky at times. And based on certain conditions, a particular method may not work at some point, leaving you searching for alternatives.</p>
<p>In this article, you will learn how to center an image in a <code>div</code> with CSS.</p>
<h2 id="heading-how-to-center-a-div-using-css">How to Center a <code>div</code> using CSS</h2>
<p>You center an image in a <code>div</code> in two ways: horizontally and vertically. When you put these two methods together, you will have an entirely centered image:</p>
<p><img src="https://paper-attachments.dropbox.com/s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660599829888_Untitled.png" alt="s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660599829888_Untitled" width="600" height="400" loading="lazy"></p>
<p>By default, web content always begins from the top-left corner of the screen and moves from <code>ltr</code> (left to right) – except for certain languages like Arabic, which goes from <code>rtl</code> (right to left).</p>
<p>Let’s start by seeing how to center an image within a <code>div</code> horizontally. Then we'll see how to center vertically. Finally, we'll see how you can do both together.</p>
<p><img src="https://paper-attachments.dropbox.com/s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660702367688_image.png" alt="s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660702367688_image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-an-image-in-a-div-horizontally-with-text-align">How to Center an Image in a Div Horizontally with Text-align</h3>
<p>Suppose you have a <code>div</code> in which you place your image this way:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./fcc-logo.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"FCC Logo"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>And apply basic CSS styling so your image is visible:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
}
<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p>The <code>text-align</code> method won't work in all cases, as you typically use it to center text. But when you have your images within a block level container like a <code>div</code>, then this method will work:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">text-align</span>: center;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p>This works by adding the <code>text-align</code> property alongside its value of <code>center</code> to the container and not the image itself.</p>
<h3 id="heading-how-to-center-an-image-in-a-div-horizontally-with-margin-auto">How to Center an Image in a Div Horizontally with Margin-auto</h3>
<p>Another method that you can use to horizontally center an image within a <code>div</code> (container) is the <code>margin</code> property with the value of <code>auto</code>.</p>
<p>The element will then take up the <strong>specified</strong> <code>width</code>, and the remaining space will be split equally between the left and right margins.</p>
<p>You would usually apply this method to the image itself and not the container. But unfortunately, this property alone doesn't work. You also need to specify the <code>width</code> the image will take first. This lets the margin know the remaining width the container has so that it can be split equally.</p>
<p>Secondly, <code>img</code> is an inline element, and the <code>margin-auto</code> property set does not affect inline-level elements. This means you must first convert it to a block-level element with <code>display</code> property set as <code>block</code>.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">margin</span>: auto;
    <span class="hljs-attribute">display</span>: block;
}
</code></pre>
<h3 id="heading-how-to-center-an-image-in-a-div-horizontally-with-the-position-and-transform-properties">How to Center an Image in a Div Horizontally with the Position and Transform Properties</h3>
<p>Another method you can use to position an image horizontally is the <code>position</code> property alongside the <code>transform</code> property.</p>
<p>This method can be very tricky, but it works. You must first set the container’s <code>position</code> to <code>relative</code>, then the image to <code>absolute</code>.</p>
<p>Once you do this, you can now move the image to whichever position you wish using either the <code>left</code>, <code>top</code>, <code>bottom</code>, or <code>right</code> properties on the image.</p>
<p>In this case, you only want to move the image to the center horizontally. This means you would move the image via the <code>left</code> to 50% or <code>right</code> to -50%:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
}
</code></pre>
<p>But when you check your image, you will notice that the image is still not perfectly placed in the center. This is because it started from the 50% mark, which is the center position.</p>
<p>In this case, you need to use the <code>transform-translateX</code> property to adjust it to get the perfect center horizontally:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(-<span class="hljs-number">50%</span>);
}
</code></pre>
<h3 id="heading-how-to-center-an-image-in-a-div-horizontally-with-display-flex">How to Center an Image in a Div Horizontally with Display-Flex</h3>
<p>CSS flexbox makes it easier for you to design flexible, responsive layout structures without using float or positioning. We can also use this to place an image in the center horizontally of a container using the display property with flex as its value.</p>
<p>But this alone doesn't work. You also need to define the position where you want your image. This could be <code>center,</code> <code>left</code> or maybe <code>right</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: center;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p><strong>Note:</strong> The <code>display: flex</code> property is not supported in older versions of browsers. You can read more <a target="_blank" href="https://caniuse.com/#search=display%20flex">here</a>. You’ll also notice that the width and height of the image are defined to ensure the image doesn't shrink.</p>
<p>Let’s now learn how to center an image in a <code>div</code> vertically. Later we'll see how to center an image in a <code>div</code> horizontally and vertically together, making it a perfect center.</p>
<p><img src="https://paper-attachments.dropbox.com/s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660702330431_image.png" alt="s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660702330431_image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-an-image-in-a-div-vertically-with-display-flex">How to Center an Image in a Div Vertically with Display-Flex</h3>
<p>Just like how you were able to center the image horizontally with the display-flex method, you can also do the same vertically.</p>
<p>But this time around, you won’t need to use the <code>justify-content</code> property. Rather you'll use the <code>align-items</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p>For this method to work, the container must have a specified <code>height</code> which you will use to calculate the height and know where the center is located.</p>
<h3 id="heading-how-to-center-an-image-in-a-div-vertically-with-the-position-and-transform-properties">How to Center an Image in a Div Vertically with the Position and Transform Properties</h3>
<p>Similar to how you used the <code>position</code> and <code>transform</code> properties earlier to place your image in the center horizontally, you can also do the same vertically.</p>
<p>But this time around, you won't use <code>left</code> or <code>right,</code>. Instead you will use <code>top</code> or <code>bottom</code> alongside <code>translateY</code> rather than <code>translateX</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">50%</span>);
}
</code></pre>
<p>You have learned how to center an image within a <code>div</code> horizontally and vertically using all possible methods. Let’s now learn how to center both horizontally and vertically.</p>
<p><img src="https://paper-attachments.dropbox.com/s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660702293626_image.png" alt="s_E4F69027FF573CB7A65859895F7B6CD8342925344584ACB8BE37F8B299430A72_1660702293626_image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-an-image-in-a-div-horizontally-and-vertically-with-display-flex">How to Center an Image in a Div Horizontally and Vertically with Display-Flex</h3>
<p>The <code>display-flex</code> property is a combination of how you'd center the image vertically and horizontally.</p>
<p>For the flex method, this means you will use both the <code>justify-content</code> and <code>align-items</code> properties set to <code>center</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<h3 id="heading-how-to-center-an-image-in-a-div-horizontally-and-vertically-with-the-position-and-transform-properties">How to Center an Image in a Div Horizontally and Vertically with the Position and Transform Properties</h3>
<p>This is also very similar, as all you have to do is combine both ways you were able to center vertically and horizontally:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateX</span>(-<span class="hljs-number">50%</span>) <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">50%</span>);
}
</code></pre>
<p>You can also combine the <code>translateX</code> and <code>translateY</code> by using <code>translate(x,y)</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">200px</span>;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0a0a23</span>;
    <span class="hljs-attribute">position</span>: relative;
}

<span class="hljs-selector-class">.container</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
    <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>, -<span class="hljs-number">50%</span>);
}
</code></pre>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this article, you have learned how to center an image in a div vertically, horizontally, or both.</p>
<p>You will often use the Flexbox method when moving an image to the center because the <code>position</code> method can distort your web page and works very trickily.</p>
<p>You can learn more about the <a target="_blank" href="https://www.freecodecamp.org/news/css-position-property-explained/">CSS position method here</a> and then more about the <a target="_blank" href="https://www.freecodecamp.org/news/css-flexbox-tutorial-with-cheatsheet/">flexbox method here.</a></p>
<p>Have fun coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Center a Div with CSS ]]>
                </title>
                <description>
                    <![CDATA[ There are a few common coding problems you might encounter when you start practicing what you've learned by building projects. One common problem you'll face as a web developer is how to place an element at the center of a page or within an element a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-center-a-div-with-css/</link>
                <guid isPermaLink="false">66b0a2c23dc92ea6a5a091e4</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ihechikara Abba ]]>
                </dc:creator>
                <pubDate>Wed, 27 Apr 2022 19:58:59 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/pexels-pixabay-161043-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>There are a few common coding problems you might encounter when you start practicing what you've learned by building projects.</p>
<p>One common problem you'll face as a web developer is how to place an element at the center of a page or within an element acting as its container. It's the ubiquitous "How do I center a div?" problem.</p>
<p>In this article, we'll see how we can center elements using various CSS properties. We'll see code examples in each section and a visual representation of the elements in all the examples.</p>
<h2 id="heading-how-to-center-a-div-using-the-css-flexbox-property">How to Center a Div Using the CSS Flexbox Property</h2>
<p>In this section, we'll see how we can use the CSS Flexbox property to center an element horizontally, vertically, and at the center of a page/container.</p>
<p>You can use an image if you prefer that, but we'll just use a simple circle drawn with CSS. Here's the code:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>

      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"circle"</span>&gt;</span>

      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
}

<span class="hljs-selector-class">.circle</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: black;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--276-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Positioning with Flexbox requires that we write the code in the parent or container element's class.</p>
<h3 id="heading-how-to-center-a-div-horizontally-using-flexbox">How to Center a Div Horizontally Using Flexbox</h3>
<p>Now we'll write the code to center the <code>div</code> element horizontally. We're still making use of the circle we created above.  </p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
}

<span class="hljs-selector-class">.circle</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: black;
}
</code></pre>
<p>We've added two lines of code to center the circle horizontally. These are the lines we added:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">flex</span>;
<span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">center</span>;
</code></pre>
<p><code>display: flex;</code> allows us to use Flexbox and its properties, while <code>justify-content: center;</code> aligns the circle to the center horizontally. </p>
<p>Here is the position of our circle:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--278-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-a-div-vertically-using-flexbox">How to Center a Div Vertically Using Flexbox</h3>
<p>What we'll be doing in this section is similar to the last one, except for one line of code.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-selector-class">.circle</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: black;
}
</code></pre>
<p>In this example, we used <code>align-items: center;</code> to center the circle vertically. Recall that we are required to write <code>display: flex;</code> first before specifying the direction.</p>
<p>Here's the position of our circle:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--280-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-position-a-div-at-the-center-using-flexbox">How to Position a Div at the Center Using Flexbox</h3>
<p>In this section, we'll position the circle at the center of the page using both the horizontal and vertical alignment properties of CSS Flexbox. Here's how:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">align-items</span>: center;
}

<span class="hljs-selector-class">.circle</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: black;
}
</code></pre>
<p>Here are the three lines of code we added to the container class above:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">flex</span>;
<span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">center</span>;
<span class="hljs-selector-tag">align-items</span>: <span class="hljs-selector-tag">center</span>;
</code></pre>
<p>As expected, we begin with <code>display: flex;</code> which allows us to use Flexbox in CSS. We then used both the <code>justify-content</code> (horizontal alignment) and <code>align-items</code> (vertical alignment) properties to position the circle at the center of the page.</p>
<p>Here is the position of our circle:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--282-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-center-a-div-horizontally-using-the-css-margin-property">How to Center a Div Horizontally Using the CSS <code>margin</code> Property</h2>
<p>In this section, we'll be using the <code>margin</code> property to center our circle horizontally.</p>
<p>Let's create our circle again.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>

      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"circle"</span>&gt;</span>

      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
}

<span class="hljs-selector-class">.circle</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: black;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--276-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This time we'll write the code in the <code>circle</code> class. Here's how:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
}

<span class="hljs-selector-class">.circle</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">background-color</span>: black;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
}
</code></pre>
<p>All we've added is the <code>margin: 0 auto;</code> line of code to the <code>circle</code> class.</p>
<p>Let's have a look at the position of the circle:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--278--1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-center-text-horizontally-using-the-css-text-align-property">How to Center Text Horizontally Using the CSS <code>text-align</code> Property</h2>
<p>In this section, we'll see how to center text horizontally.</p>
<p>This method only works when we are working with text written within an element.</p>
<p>Here is an example:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello World!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<p>In the example above, we have created a <code>div</code> with a class of container and a <code>h1</code> element with some text. This is what it looks like at the moment:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--272-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let's write the CSS code.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">250px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">outline</span>: solid <span class="hljs-number">1px</span> black;
}

<span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">text-align</span>: center;
}
</code></pre>
<p>In other to align the text in the <code>h1</code> element at the center of the page, we had to use the <code>text-align</code> property, giving it a value of <code>center</code>. Here's what it looks like now in the browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/04/Screenshot--274-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we saw how we can center elements horizontally, vertically, and at the center of the page using Flexbox and the margin and text-align properties in CSS.</p>
<p>In each section, we saw both a code example and a visual representation of what the code does.</p>
<p>Happy coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Flexbox Tutorial – How to Build a Fixed Side and Bottom Navbar ]]>
                </title>
                <description>
                    <![CDATA[ Flexbox can help you simplify the process of creating both basic and advanced layouts. And it's pretty straightforward to create side and bottom navigation menus with CSS flexbox or Grid. These layouts are so popular that they appear almost everywher... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/fixed-side-and-bottom-navbar-with-css-flexbox/</link>
                <guid isPermaLink="false">66d461543a8352b6c5a2ab23</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Spruce Emmanuel ]]>
                </dc:creator>
                <pubDate>Tue, 28 Sep 2021 21:41:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/09/halacious-weRQAu9TA-A-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Flexbox can help you simplify the process of creating both basic and advanced layouts. And it's pretty straightforward to create side and bottom navigation menus with CSS <code>flexbox</code> or <code>Grid</code>.</p>
<p>These layouts are so popular that they appear almost everywhere on the web. For example, check out Twitter's sidebar, which inspired this article:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/Web-capture_25-9-2021_181148_twitter.com-1.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Normally, to create a fixed menu with CSS you would have to use the <code>position</code> property with a value of either <code>fixed</code> or <code>sticky</code>.</p>
<p>The problem with this approach is that it takes the entire element out of the document flow like it was never there at all. This is one of those frustrating moments in CSS for beginners and sometimes even experts.</p>
<p>In this tutorial you'll learn how to create a fixed sidebar and fixed bottom navigation menu with CSS <code>flexbox</code> instead. I'll host all code and demos on Codepen so you can see a live preview of what we'll build.</p>
<h2 id="heading-getting-started">Getting Started</h2>
<p>To create a fixed element with Flexbox, you first need to disable scrolling on the parent element of the item you want to make fixed. In our case, the parent element is the <code>body</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">overflow</span>: hidden;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
}
</code></pre>
<h2 id="heading-the-mark-up">The Mark-up</h2>
<p>We'll use HTML to create a two column layout wrapped in a <code>div</code> called <code>wrapper</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"wrapper"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">aside</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>Item<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      ...
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">aside</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"wrapper_inner"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
        ...  
       <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
     <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<h2 id="heading-the-css">The CSS</h2>
<p>To make the sidebar fixed, we just need to disable scrolling on the parent <code>body</code> and make the <code>main</code> element scrollable.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">overflow</span>: hidden;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
}
<span class="hljs-selector-tag">main</span> {
  <span class="hljs-attribute">overflow-y</span>: auto;
}
<span class="hljs-selector-tag">aside</span> {
  <span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span> <span class="hljs-number">0</span> <span class="hljs-number">10%</span>;
}
<span class="hljs-selector-class">.wrapper</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
}
</code></pre>
<p>Let's break down this code a bit.</p>
<p>First we made the <code>body</code> non-scrollable and hid the scrollbars with this code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
    <span class="hljs-attribute">overflow</span>: hidden;
}
</code></pre>
<p>Then using <code>overflow: auto</code>, we added the scrollbars back to the <code>main</code> element.</p>
<p>And then finally, we created a flex container <code>wrapper</code> and gave it a height equal to the parent using <code>height: 100%</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.wrapper</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
}
</code></pre>
<h2 id="heading-how-to-make-it-mobile-friendly">How to Make it Mobile-friendly</h2>
<p>But on a mobile screen with a width less than <code>500px</code> we'll want the sidebar to be fixed to the bottom or top as the case may be. To do that you'll add the following CSS:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">500px</span>) {
  <span class="hljs-selector-class">.wrapper</span> {
    <span class="hljs-attribute">flex-direction</span>: column-reverse;
  }
  <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: space-between;
  }

}
</code></pre>
<p>Here on a mobile screen we change the direction of our flex wrapper to column instead of row. Then to make it fix to the bottom, we add the following:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.wrapper</span> {
    <span class="hljs-attribute">flex-direction</span>: column-reverse;
}
</code></pre>
<p>To make it fixed to the top, on the other hand, you just have to remove the <code>column-reverse</code> and change it to <code>column</code> like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.wrapper</span> {
    <span class="hljs-attribute">flex-direction</span>: column;
}
</code></pre>
<p>You can see a live preview in the pen created with Codepen below. You can resize the window to see the fixed bottom nav:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/Spruce_khalifa/embed/XWgxabX" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p> </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this tutorial you learned how to create a responsive fixed sidebar with <code>flexbox</code>. Here are some important steps to remember:</p>
<ol>
<li><p>To make an element fixed with flexbox, you have to disable scrolling on the parent element with <code>overflow: hidden</code></p>
</li>
<li><p>Then you need to create a flex container with height equal to parent</p>
</li>
<li><p>Add <code>overflow: auto</code> to the element you don't want fixed</p>
</li>
</ol>
<p>And that's it!</p>
<p>If you found this tutorial useful or have any questions, please feel free to connect with me on Twitter (don't forget to hit the follow button) <a target="_blank" href="https://twitter.com/iamspruce.dev/">@sprucekhalifa</a>.</p>
<p>Oh and happy Coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Flexbox and Grid Tutorial – How to Build a Responsive Landing Page with HTML and CSS ]]>
                </title>
                <description>
                    <![CDATA[ In this tutorial, we are going to build a simple landing page for an online education platform called Skilllz. This tutorial will teach you how to use and implement CSS Flexbox and CSS Grid alignment. We'll also cover many other CSS concepts. And fin... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-flexbox-and-grid-tutorial/</link>
                <guid isPermaLink="false">66d461793dce891ac3a9683e</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kingsley Ubah ]]>
                </dc:creator>
                <pubDate>Wed, 08 Sep 2021 17:16:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/09/SkilllzLanding.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this tutorial, we are going to build a simple landing page for an online education platform called <strong>Skilllz.</strong></p>
<p>This tutorial will teach you how to use and implement CSS Flexbox and CSS Grid alignment. We'll also cover many other CSS concepts. And finally, we'll learn how to make the page responsive so that it works on all screen sizes.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/ezgif.com-gif-maker.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The tutorial is divided into five parts:</p>
<ul>
<li><p>How to Build the Navigation Bar</p>
</li>
<li><p>How to Build the Showcase Section</p>
</li>
<li><p>How to Build the Lower Section</p>
</li>
<li><p>How to Build the Footer Section</p>
</li>
<li><p>How to Make the Page Responsive</p>
</li>
</ul>
<p>Each of these sections will teach you some new CSS and web development skills and tools. So let's jump right in.</p>
<h2 id="heading-how-to-create-the-html-boilerplate">How to Create the HTML Boilerplate</h2>
<p>If you have emmet installed in your IDE, you can generate an HTML boilerplate for your project by typing <code>!</code> and clicking the <code>enter</code> or <code>tab</code> key on your keyboard.</p>
<p>If not, you can copy this boilerplate code and paste it into your code editor:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"ie=edge"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"styles.css"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"</span> <span class="hljs-attr">integrity</span>=<span class="hljs-string">"sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ=="</span>
  <span class="hljs-attr">crossorigin</span>=<span class="hljs-string">"anonymous"</span> <span class="hljs-attr">referrerpolicy</span>=<span class="hljs-string">"no-referrer"</span> /&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-how-to-use-font-awesome-icons">How to Use Font Awesome Icons</h3>
<p>As you can see in one of the shots, we will be using some font icons to give better swap to our service section.</p>
<p>For this, we will be using font awesome from the CDN. If you created an HTML biolerplate by yourself, copy the following <code>link</code> tag and paste it into your <code>head</code> tag:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"</span> <span class="hljs-attr">integrity</span>=<span class="hljs-string">"sha512-1ycn6IcaQQ40/MKBW2W4Rhis/DbILU74C1vSrLJxCq57o941Ym01SwNsOMqvEBFlcgUa6xLiPY/NS5R+E6ztJQ=="</span>
  <span class="hljs-attr">crossorigin</span>=<span class="hljs-string">"anonymous"</span> <span class="hljs-attr">referrerpolicy</span>=<span class="hljs-string">"no-referrer"</span> /&gt;</span>
</code></pre>
<h2 id="heading-lets-get-started">Let's Get Started</h2>
<p>First, make sure that your stylesheet file (.css) is properly linked to your HTML page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/test.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-build-the-navigation-bar">How to Build the Navigation Bar</h2>
<p>The Navigation Bar section is going to be comprised of our site's name as well as two navigation links: <code>Log in</code> and <code>check courses</code>.</p>
<p>Here is the markup for our navbar:</p>
<pre><code class="lang-js">&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"navbar"</span>&gt;
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container flex"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"logo"</span>&gt;</span>Skilllz<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"outline"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span>Log in<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">li</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"outline"</span>&gt;</span>Check courses<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>                 &lt;/<span class="hljs-attr">li</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<p>On the div wrapping the elements inside this section (the navbar), we register the container and flex class.</p>
<ul>
<li><p><code>.container</code>: we will use this utility class in every section to make sure that the inner elements do not exceed a certain width which we'll specify in CSS</p>
</li>
<li><p><code>.flex</code>: we will use this utility class to display children elements in a horizontally aligned manner (side-by-side) using CSS Flexbox.</p>
</li>
</ul>
<p>Inside the <code>div</code> we have an <code>h1</code> with class of <code>logo</code> and two navigation links <code>li&gt;a</code> with the <code>outline</code> classes, respectively.</p>
<p>At this point, our page will look all plain and bare like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navbarHTML1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>No CSS yet</em></p>
<h3 id="heading-how-to-apply-css-styling-to-our-page">How to Apply CSS Styling to our Page</h3>
<p>We now have to apply some CSS rules to style our nav section the way we want. What we want to do first is set the base styling for our web page with the following code:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Override default style and set padding and margin to nothing */</span>

* {
  <span class="hljs-attribute">box-sizing</span>: border-box;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>
}

<span class="hljs-comment">/* White text throughout */</span>

<span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">"lato"</span>, sans-serif;
  <span class="hljs-attribute">color</span>: white;
}

<span class="hljs-comment">/* Make all link text black with no text decoration */</span>
<span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: black;
  <span class="hljs-attribute">text-decoration</span>: none;
}


<span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">600</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.2</span>;
}


<span class="hljs-selector-tag">h2</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">25px</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">300</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.2</span>;
}

<span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">30px</span>;
}

<span class="hljs-comment">/* All images must not be larger than parent container */</span>
<span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
}

<span class="hljs-comment">/* No styling on list items */</span>
<span class="hljs-selector-tag">li</span> {
  <span class="hljs-attribute">list-style-type</span>: none;
}



<span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
}
</code></pre>
<p>With the default styles applied, our page will now look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navbarHTML2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Next, we need to define the styling for our container class:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Centers it, sets a maximum width and makes sure elements can flow past it*/</span>

<span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">1200px</span>;
  <span class="hljs-attribute">overflow</span>: visible;
}
</code></pre>
<p>Now, our content will not exceed the maximum width specified.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navbarHTML3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>After that, we need to set the background color of our navbar section to purple:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Sets background color, height and padding*/</span>

<span class="hljs-selector-class">.navbar</span> {
  <span class="hljs-attribute">background-color</span>: purple;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">70px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span> <span class="hljs-number">30px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navbarHTML4.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Then we target only the <code>h1</code> element inside the <code>navbar</code> and specify the following styles:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Sets font size, reduces font-weight, adds margin and line height */</span>

<span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-tag">h1</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">font-weight</span>: <span class="hljs-number">300</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.2</span>;
}
</code></pre>
<p>With that style applied, our <code>h1</code> heading will look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navbarH5.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now we need to display both child elements inside the container <code>h1</code> and <code>nav</code> side-by-side using Flexbox.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-class">.flex</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-between;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
}
</code></pre>
<p>First, we set the display mode to <code>flex</code>. This will align the elements side by side <strong>by default</strong>.</p>
<p>We then justify the content, adding a considerable space between each item using the <code>space-between</code> value. We align the items to appear at the center (middle) of the container and set its height to take up the entire container.</p>
<p>This is what our page should now look like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navrbarH6.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Cool right?</em></p>
<p>However, we also do not want both of our navigation link stacked on top of each other. Instead, we want them to be displayed side-by-side. Guess how we do that? With Flexbox!</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-tag">ul</span> {
  <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-comment">/* Changes the color of both links to white, adds padding between them and margin as well */</span>

<span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: white;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">9px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
}
</code></pre>
<p>Our page will now look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/navbarH7.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The power of CSS flexbox</em></p>
<p>If you watched the brief intro video, you will notice that whenever I hover over any of the links, the text color changes to a lighter shade of purple and a solid border appears below it.</p>
<p>We can implement this transition using the CSS <code>:hover</code> pseudo-element:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#9867C5</span>;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">3px</span> solid <span class="hljs-number">#9867C5</span>;
}
</code></pre>
<p>Now watch this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/ezgif.com-gif-maker--1-.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Hover effect on the links</em></p>
<p>And with that, we have come to the end of the navbar section.</p>
<h2 id="heading-how-to-build-the-showcase-area">How to Build the Showcase Area</h2>
<p>The showcase area is going to house the headline text, supporting text, a form for signing up new users, as well as a headline image.</p>
<p>This section is going to be divided in two: the left side and the right side. In other words, it will be displayed as a grid of two units.</p>
<p>Here is the markup for this section:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"showcase"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid-item-1"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"showcase-text"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Learn any digital skill of your choice today<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"supporting-text"</span>&gt;</span> Over 30,000 students currently learn with us<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"showcase-form"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">form</span> <span class="hljs-attr">action</span>=<span class="hljs-string">""</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"email"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Enter your email address"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"btn"</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"Start Learning"</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"little-info"</span>&gt;</span>Try out our free courses today. No risk, no credit card required<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid-item-2"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"image"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./images/transparent.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
           <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>Currently, our app is going to look a bit messy:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/showcaseH1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-apply-css-styling-to-our-showcase-area">How to Apply CSS Styling to our Showcase Area</h3>
<p>First, we set the height of the showcase section as well as a background color:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.showcase</span> {
  <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
  <span class="hljs-attribute">background-color</span>: purple;
}
</code></pre>
<p>Our app will now look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/showcaseH2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Still messy</em></p>
<blockquote>
<p>NOTE: I changed the color of <code>h1</code> to white</p>
</blockquote>
<p>Next, we apply the following styles:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Adds margin below the text */</span>
<span class="hljs-selector-class">.showcase</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">30px</span>;
}

<span class="hljs-comment">/* Adds a shadow below the image */</span>
<span class="hljs-selector-class">.showcase</span> <span class="hljs-selector-tag">img</span> {
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">7px</span> <span class="hljs-number">7px</span> <span class="hljs-number">7px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.2</span>);
}

<span class="hljs-comment">/* Adds some padding on the form content */</span>
<span class="hljs-selector-class">.showcase-form</span> {
  <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">7px</span>;
}
</code></pre>
<p>This brings us to the main activity. If you remember, I said that we were going to be creating two sections (grids) inside the showcase container. With the grid class registered on that container, we can align its content using CSS grid display like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid</span> {
  <span class="hljs-attribute">overflow</span>: visible;
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">60%</span> <span class="hljs-number">40%</span>;
}
</code></pre>
<p>This will create two columns inside of our showcase container. The first part will take up 60 percent of the container, and the second part will take up the remaining 40 percent of the container.</p>
<p>The overflow visible will ensure that the image (if bigger than the container) will flow beyond the container.</p>
<p>Our app will now look like this</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/showcaseH3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Next, we need to set some space between the navigation area and the showcase area.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item-1</span>,
<span class="hljs-selector-class">.grid-item-2</span> {
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50px</span>;
}
</code></pre>
<p>As a result, it is now spaced out a bit:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/showcaseH4.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now, we need to style both of our form inputs because they don't look so nice. We select the first input by its type (email) and select the second by its class name, <code>btn</code>.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.showcase</span> <span class="hljs-selector-tag">input</span><span class="hljs-selector-attr">[type=<span class="hljs-string">'email'</span>]</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-number">70px</span> <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">14px</span>;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">6px</span>;
  <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">6px</span>;
}

<span class="hljs-selector-class">.btn</span> {
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">6px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">12px</span> <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#9867C5</span>;
  <span class="hljs-attribute">border</span>: none;
  <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">color</span>: white;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
  <span class="hljs-attribute">cursor</span>: pointer;
  <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">10px</span> <span class="hljs-number">10px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.2</span>);
}
</code></pre>
<p>This style will transform both our form inputs to this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/showcaseH5-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Form input styled better</em></p>
<p>Also maybe change the font of the supporting text:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.showcase-form</span> {
  <span class="hljs-attribute">margin</span>: auto;
}

<span class="hljs-comment">/* Change typeface and its size */</span>
<span class="hljs-selector-class">.little-info</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">15px</span>;
  <span class="hljs-attribute">font-family</span>: <span class="hljs-string">"poppins"</span>, sans-serif;

}
</code></pre>
<p>This is the final look of our showcase section:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/showcaseH7.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Final look of showcase section</em></p>
<p>That's it for this section!</p>
<h2 id="heading-how-to-build-the-lower-part-of-the-page">How to Build the Lower Part of the Page</h2>
<p>The lower part of the page is going to contain two sections, the <strong>stats</strong> section and the <strong>testimonials</strong> section.</p>
<p>The stats container which displays the services offered by <strong>Skilllz</strong> will be made up of three <code>div</code>s, each of which houses a font awesome icon, an <code>h3</code> of class <code>title</code>, and a paragraph <code>p</code> of class <code>text</code>.</p>
<p>The testimonial container will hold the testimonials of three random people who learned using Skillz. I grabbed the pictures from <a target="_blank" href="https://unsplash.com/s/photos/random-people">unsplash</a>.</p>
<h3 id="heading-how-to-build-the-stats-section">How to Build the Stats Section</h3>
<p>First, we are going to work on the stats section. The text is just a dummy 'lorem50' text to act as a filler for this demo.</p>
<p>Here is the markup for it:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"lower-container container"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"stats"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"stat"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fa fa-folder-open fa-2x"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>&gt;</span>Over 300 available courses<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
              Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"stat"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fa fa-graduation-cap fa-2x"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>&gt;</span>Free certificate offered on all courses<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
              Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"stat"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fa fa-credit-card-alt fa-2x"</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">"true"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"title"</span>&gt;</span>Book 1on1 session for as low as $5<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text"</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
              Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<p>This section will be displayed as a blank page. This is because we had set the color of our text in the whole body to white. So we have to add some styling.</p>
<h3 id="heading-how-to-apply-css-styling-to-the-stats-section">How to Apply CSS Styling to the Stats Section</h3>
<p>First we need to apply the following styles:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Centers the container, sets a maximum width
.lower-container {
  margin: 120px auto;
  padding: 0;
  max-width: 1400px;
}


/* Targets all h3 with class of title */</span>
<span class="hljs-selector-class">.title</span> {
  <span class="hljs-attribute">color</span>: black;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">text-align</span>: left;
  <span class="hljs-attribute">padding-left</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">padding-top</span>: <span class="hljs-number">10px</span>;
}

<span class="hljs-comment">/* Targets the paragraphs with class name of text */</span>
<span class="hljs-selector-class">.text</span> {
  <span class="hljs-attribute">color</span>: black;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">19px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>, <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">text-align</span>: justify;
}
</code></pre>
<p>This will now make our text visible:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/lower1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Notice that the font icons from Font Awesome are not visible. We will be working on that pretty soon.</p>
<p>But before then, we will need to do something important. We do intend for all of the three stat <code>div</code>s to be aligned horizontally (side-by-side). To achieve that, we will once again be using CSS Flexbox:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Display horizontally, put a little space around them */</span>
<span class="hljs-selector-class">.flex</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">justify-content</span>: space-around;
}

<span class="hljs-comment">/* Add some padding around the container. Align text centrally */</span>
<span class="hljs-selector-class">.stats</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">45px</span> <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">text-align</span>: center;
}

<span class="hljs-comment">/* Set margin and width */</span>
<span class="hljs-selector-class">.stat</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">30px</span>;
  <span class="hljs-attribute">text-align</span>: center;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">800px</span>;
}
</code></pre>
<p>This is how our app will now look:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/lower2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Still no icons? Time to fix that!</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.stats</span> <span class="hljs-selector-class">.fa</span> {
  <span class="hljs-attribute">color</span>: purple;
}
</code></pre>
<p>and voilà!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/lower4.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-build-the-testimonials-section">How to Build the Testimonials Section</h3>
<p>The second section inside of the lower container <code>div</code> of the page is the testimonials section. This section is going to be made up of three cards, each of which contains the image of the person (clipped inside a circle), their name, and the person's testimonial.</p>
<p>Here is the markup for that:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"testimonials"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"testimonial grid-3"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"circle"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./images/4.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Aston<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I have learnt web development using this platfrom and I am going to say this is the best platform for learning. Absolutely
            worth the investment!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"circle"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./images/5.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Beth<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I have learnt copywriting using this platfrom and I am going to say this is the best platform for learning. Absolutely
            worth the investment!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"card"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"circle"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"./images/6.jpg"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">""</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Chris<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I have learnt affilitate marketing using this platfrom and I am going to say this is the best platform for learning. Absolutely
            worth the investment!<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
<h3 id="heading-how-to-apply-css-styling-to-it">How to Apply CSS Styling to it</h3>
<p>First, we set the text color to black so we can see it:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.testimonial</span> {
  <span class="hljs-attribute">color</span>: black;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">40px</span>;
}
</code></pre>
<p>When applied, it should make the text visible and add some padding to the section:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/testi1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Next, we set the image to take up the height of its parent container:</p>
<pre><code class="lang-css">
<span class="hljs-comment">/* Wrap the image inside a cirle shape and set height to take up all of parent element */</span>

<span class="hljs-selector-class">.testimonial</span> <span class="hljs-selector-tag">img</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">clip-path</span>: <span class="hljs-built_in">circle</span>();
}

<span class="hljs-comment">/* Align text centrally */</span>

<span class="hljs-selector-class">.testimonial</span> <span class="hljs-selector-tag">h3</span>{
  <span class="hljs-attribute">text-align</span>: center;
}
</code></pre>
<p>If you check the final layout in the gif, you will notice that all three testimonial cards are aligned side-by-side on the same line.</p>
<p>So we will need to create a div of three equal columns using the CSS grid arrangement.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Create a grid of three equal columns. Set a gap of 40 px between them */</span>

<span class="hljs-selector-class">.grid-3</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">3</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">40px</span>;
}


<span class="hljs-comment">/* Create a white card with some shadow around it */</span>
<span class="hljs-selector-class">.card</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">background-color</span>: white;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">box-shadow</span>: -<span class="hljs-number">7px</span> -<span class="hljs-number">7px</span> <span class="hljs-number">20px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.2</span>),
               <span class="hljs-number">7px</span>  <span class="hljs-number">7px</span> <span class="hljs-number">20px</span> <span class="hljs-built_in">rgba</span>(<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0.2</span>)
}
</code></pre>
<p>With all of these styles applied, the testimonials section will now look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/testi2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Finally, we style the circle <code>div</code> and position it relative to the top border of the card using CSS:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.circle</span> {
    <span class="hljs-attribute">background-color</span>: transparent;
    <span class="hljs-attribute">border</span>:<span class="hljs-number">3px</span> solid purple;
    <span class="hljs-attribute">height</span>:<span class="hljs-number">90px</span>;
    <span class="hljs-attribute">position</span>: relative;
    <span class="hljs-attribute">top</span>: -<span class="hljs-number">30px</span>;
    <span class="hljs-attribute">left</span>: <span class="hljs-number">120px</span>;
    <span class="hljs-attribute">border-radius</span>:<span class="hljs-number">50%</span>;
    <span class="hljs-attribute">-moz-border-radius</span>:<span class="hljs-number">50%</span>;
    <span class="hljs-attribute">-webkit-border-radius</span>:<span class="hljs-number">50%</span>;
    <span class="hljs-attribute">width</span>:<span class="hljs-number">90px</span>;
}
</code></pre>
<p>And here is how everything will look in our browser:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/testi4.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Final look</em></p>
<p>Alright, now we're ready to move on to the footer section. Then we'll learn how to make the site responsive.</p>
<h2 id="heading-how-to-build-the-footer-section">How to build the Footer Section</h2>
<p>The final part of our landing page building process is to create the footer section. The footer section will comprise some copyright text, three extra navigation links, and a group of social media icons from Font Awesome.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/ezgif.com-gif-maker--2-.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Here is the HTML Markup for the footer section of our landing page:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container grid-3"</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"copyright"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Skilllz<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Copyright <span class="hljs-symbol">&amp;copy;</span> 2021<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
     <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"links"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"outline"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"outline"</span>&gt;</span>Tutors<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"outline"</span>&gt;</span>Categories<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
     <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"profiles"</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fab fa-twitter fa-2x"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fab fa-instagram fa-2x"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fab fa-facebook fa-2x"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
       <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">""</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fab fa-whatsapp fa-2x"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
     <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
<p>The footer section will look unattractive without any styling:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/footer-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>No CSS yet</em></p>
<p>So let's change that.</p>
<h3 id="heading-how-to-style-the-footer">How to Style the Footer</h3>
<p>First, we need to set the background colour for the footer section (as well as the color for all links) to white, like this:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Add padding around the footer as well */</span>

<span class="hljs-selector-tag">footer</span> {
  <span class="hljs-attribute">background-color</span>: purple;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span> <span class="hljs-number">10px</span>;
}

<span class="hljs-comment">/* Sets all link texts to white and puts margin to the left and right */</span>

<span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: white;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> <span class="hljs-number">10px</span>;
}
</code></pre>
<p>Now the footer will look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/footer3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Footer</em></p>
<p>If you check the first gif, you will notice that when I hover over any of the links inside of the footer, their color changes to a lighter shade of purple and a border also appears below them.</p>
<p>We can make this happen using a <code>:hover</code> selector:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#9867C5</span>;
  <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#9867C5</span>;
}
</code></pre>
<p>That's all for the footer!</p>
<h2 id="heading-how-to-set-media-queries-to-make-the-page-responsive">How to Set Media Queries to Make the Page Responsive</h2>
<p>It's now time to make our landing page more responsive. When building a website, it is important to have in mind that users will be viewing the site from different devices. So it is imperative to make the site layout responsive to improve the user experience across multiple devices.</p>
<p>In our CSS, we will define media queries which set breakpoints for the various screen widths of different devices and map a set of CSS rules for each screen size.</p>
<h3 id="heading-how-to-design-for-tablets-and-smaller-screens">How to Design for Tablets and Smaller Screens</h3>
<p>First, we will optimize our site's layout for users viewing from a tablet. In our CSS, we define the following style:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Tablets and Under */</span>

<span class="hljs-keyword">@media</span>(max-width: <span class="hljs-number">768px</span>) {
  <span class="hljs-selector-class">.grid</span>,
  <span class="hljs-selector-class">.grid-3</span> {
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr;
  }
</code></pre>
<p>Initially we had set two columns for the <code>.grid</code> class and 3 columns for the <code>grid-3</code> class. Now, we want to make sure that all grid items take up just a single line.</p>
<p>As a result, our form and image which was formerly displayed side-by-side (horizontally) will now be displayed one after the other (vertically), like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/resp1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Next, we'll apply the following styles:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Align all text to the center. This will move all text, including form centrally */</span>

<span class="hljs-selector-class">.showcase</span> {
    <span class="hljs-attribute">height</span>: auto;
    <span class="hljs-attribute">text-align</span>: center;
  }

<span class="hljs-comment">/* This resets the width of the image container and adds margin space to the left */</span> 

<span class="hljs-selector-class">.image</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">80px</span>;
  }

<span class="hljs-comment">/* Changes the service sections from side-by-side orientation to each taking its own line. Aligns text to the center */</span>

<span class="hljs-selector-class">.stats</span> <span class="hljs-selector-class">.flex</span> {
    <span class="hljs-attribute">flex-direction</span>: column;
  }

  <span class="hljs-selector-class">.stats</span> {
    <span class="hljs-attribute">text-align</span>: center;
  }

<span class="hljs-comment">/* Makes sure each stat section does not exceed the width of parent */</span>

<span class="hljs-selector-class">.stat</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">padding-right</span>: <span class="hljs-number">80px</span>;
  }

<span class="hljs-comment">/* (re)Moves the cirle to the center of the card */</span>

<span class="hljs-selector-class">.circle</span> {
      <span class="hljs-attribute">background-color</span>: transparent;
      <span class="hljs-attribute">border</span>:<span class="hljs-number">3px</span> solid purple;
      <span class="hljs-attribute">height</span>:<span class="hljs-number">90px</span>;
      <span class="hljs-attribute">position</span>: relative;
      <span class="hljs-attribute">top</span>: -<span class="hljs-number">30px</span>;
      <span class="hljs-attribute">left</span>: <span class="hljs-number">270px</span>;
      <span class="hljs-attribute">border-radius</span>:<span class="hljs-number">50%</span>;
      <span class="hljs-attribute">-moz-border-radius</span>:<span class="hljs-number">50%</span>;
      <span class="hljs-attribute">-webkit-border-radius</span>:<span class="hljs-number">50%</span>;
      <span class="hljs-attribute">width</span>:<span class="hljs-number">90px</span>;
  }
</code></pre>
<p>And voilà! Our site now works on tablets and smaller screens.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/ezgif.com-gif-maker--3--1.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>The result</em></p>
<h3 id="heading-how-to-design-for-mobile-devices">How to Design for Mobile Devices</h3>
<p>Many people may view the site from a mobile device which typically has the smallest screen size out of all devices. Because of this, creating a layout for mobile-sized screens is very important.</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Mobile devices */</span>
<span class="hljs-keyword">@media</span>(max-width: <span class="hljs-number">500px</span>) {
  <span class="hljs-selector-class">.navbar</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">100px</span>;
  }
</code></pre>
<p>First, we increase the height of our navigation area. Since it will be viewed from a smaller screen, we want the area more accentuated for the user.</p>
<p>Then, we define the following styles:</p>
<pre><code class="lang-css"><span class="hljs-comment">/* Changes the alignment. The logo title stays at the top, the nav links will be below it */</span>

<span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-class">.flex</span> {
    <span class="hljs-attribute">flex-direction</span>: column;
  }


<span class="hljs-comment">/* When hovered on, retain white color and change border to black */</span>

  <span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
    <span class="hljs-attribute">color</span>: white;
    <span class="hljs-attribute">border-bottom</span>: <span class="hljs-number">2px</span> solid black;
  }


<span class="hljs-comment">/* Set light purple background on nav links, make it a bit round and add some spacing */</span>

  <span class="hljs-selector-class">.navbar</span> <span class="hljs-selector-tag">ul</span> {
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#9867C5</span>;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-number">0</span>;
  }


<span class="hljs-comment">/* Align text to center */</span>

  <span class="hljs-selector-class">.showcase</span> {
    <span class="hljs-attribute">height</span>: auto;
    <span class="hljs-attribute">text-align</span>: center;
  }


<span class="hljs-comment">/* Reduce font size */</span>

<span class="hljs-selector-class">.little-info</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">13px</span>;
  }


<span class="hljs-comment">/* Reduce image width */</span>

  <span class="hljs-selector-class">.image</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-number">350px</span>;
    <span class="hljs-attribute">margin-left</span>: <span class="hljs-number">70px</span>;
  }

  <span class="hljs-selector-class">.stat</span> {
    <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">40px</span>;
  }


<span class="hljs-comment">/* Move circle once again */</span>

<span class="hljs-selector-class">.circle</span> {
      <span class="hljs-attribute">background-color</span>: transparent;
      <span class="hljs-attribute">border</span>:<span class="hljs-number">3px</span> solid purple;
      <span class="hljs-attribute">height</span>:<span class="hljs-number">90px</span>;
      <span class="hljs-attribute">position</span>: relative;
      <span class="hljs-attribute">top</span>: -<span class="hljs-number">30px</span>;
      <span class="hljs-attribute">left</span>: <span class="hljs-number">150px</span>;
      <span class="hljs-attribute">border-radius</span>:<span class="hljs-number">50%</span>;
      <span class="hljs-attribute">-moz-border-radius</span>:<span class="hljs-number">50%</span>;
      <span class="hljs-attribute">-webkit-border-radius</span>:<span class="hljs-number">50%</span>;
      <span class="hljs-attribute">width</span>:<span class="hljs-number">90px</span>;
  }
}
</code></pre>
<p>And voilà!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/ezgif.com-gif-maker--4--1.gif" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-wrapping-up"><strong>Wrapping Up</strong></h2>
<p>FlexBox and Grid alignment are very powerful tools for laying out a web page however you want it to look.</p>
<p>Responsive web design is arguably one of the most important design principles in web development. We have to consider the fact that our site will be viewed from various kinds of devices with different screen resolutions. Optimizing our site's layout for different screens will improve the user experience.</p>
<p>In this tutorial, we have designed a simple landing page using CSS Flexbox, Grid, and many other CSS properties. We have also made the page look good on Tablets and Mobile Screens.</p>
<p>The full code for this project can be gotten from this <a target="_blank" href="https://github.com/KingsleyUbah/Skilllz">GitHub repository</a>.</p>
<p>I hope you learned something useful from this tutorial. If you have any suggestions, reach out to me on <a target="_blank" href="https://twitter.com/UbahTheBuilder">Twitter</a>. You can also visit my <a target="_blank" href="https://ubahthebuilder.tech/">blog</a> for posts like this.</p>
<p>Thanks for following along and see you soon.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Vertical Align – How to Center a Div, Text, or an Image [Example Code] ]]>
                </title>
                <description>
                    <![CDATA[ Even with helpful tools like CSS Grid and Flexbox, centering elements in CSS remains notoriously challenging.  It's been the subject of many jokes and memes, and when you successfully center something, you'll want to brag about it. Why is Centering C... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-vertical-align-how-to-center-a-div-text-or-an-image-example-code/</link>
                <guid isPermaLink="false">66adf0a02d0eb5bfdd6b0c14</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Wed, 04 Aug 2021 15:02:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/center.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Even with helpful tools like CSS Grid and Flexbox, centering elements in CSS remains notoriously challenging. </p>
<p>It's been the subject of many jokes and memes, and when you successfully center something, you'll want to brag about it.</p>
<h2 id="heading-why-is-centering-css-elements-so-hard">Why is Centering CSS Elements So Hard?</h2>
<p>CSS can be tricky to work with. For example, if you're trying to align something horizontally OR vertically, it's not that difficult.</p>
<p>You can just set text-align to center for an inline element, and <code>margin: 0 auto</code> would do it for a block-level element.</p>
<p>But issues arise on multiple fronts if you're trying to combine both vertical and horizontal alignments.   </p>
<p>In this tutorial, I will introduce you to three different methods to correctly center a div, text, or image in CSS.</p>
<h2 id="heading-how-to-center-an-element-with-the-css-position-property">How to Center an Element with the CSS Position Property</h2>
<p>The CSS position property takes relative, absolute, fixed, and static (the default) as values. When set, you will be able to apply the top, right, bottom, and left properties to the element. </p>
<p>The combination of relative and absolute values can get a lot of things done, and so you can use it to center anything. </p>
<p>Take a look at the snippets below to see some examples.</p>
<h3 id="heading-how-to-center-text-with-css-positioning">How to center text with CSS positioning</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I'm a Camper, and I'm vertically centered<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css">* {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
} 

<span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
}

<span class="hljs-selector-class">.centered-element</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">50%</span>);
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss1b.png" alt="ss1b" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-an-image-with-css-positioning">How to center an image with CSS positioning</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"freecodecamp.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"centered"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css">* {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
}

<span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">position</span>: relative;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">400px</span>;
  <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
}

<span class="hljs-selector-class">.centered-element</span> {
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
  <span class="hljs-attribute">position</span>: absolute;
  <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
  <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">50%</span>);
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss2b.png" alt="ss2b" width="600" height="400" loading="lazy"></p>
<p>The above code has made the text and image centered vertically. To take care of both vertical and horizontal centering, we need to make a little tweak in the CSS. We'll set the top property to 50%, and we'll add a transform on both the X and Y axes.</p>
<pre><code>* {
  <span class="hljs-attr">margin</span>: <span class="hljs-number">0</span>;
  padding: <span class="hljs-number">0</span>;
  box-sizing: border-box;
}

.container {
  <span class="hljs-attr">position</span>: relative;
  height: <span class="hljs-number">400</span>px;
  border: <span class="hljs-number">2</span>px solid #<span class="hljs-number">006100</span>;
}

.centered-element {
  <span class="hljs-attr">margin</span>: <span class="hljs-number">0</span>;
  position: absolute;
  top: <span class="hljs-number">50</span>%;
  left: <span class="hljs-number">50</span>%;
  transform: translate(<span class="hljs-number">-50</span>%, <span class="hljs-number">-50</span>%);
}
</code></pre><p>The text now looks like this:
<img src="https://www.freecodecamp.org/news/content/images/2021/08/ss4b.png" alt="ss4b" width="600" height="400" loading="lazy"></p>
<p>And the image like this: 
<img src="https://www.freecodecamp.org/news/content/images/2021/08/ss3b.png" alt="ss3b" width="600" height="400" loading="lazy"></p>
<p>Note that I applied the transform property because the child (with the class of centered-element) was slightly off-center. <code>translateY()</code> pushes it to the center vertically and translate on both the X and Y-axis (<code>translate()</code>) pushes it to the center vertically and horizontally. </p>
<h2 id="heading-how-to-center-an-element-with-flexbox-in-css">How to Center an Element with Flexbox in CSS</h2>
<p>CSS Flexbox handles layouts in one dimension (row or column). With Flexbox, it is pretty easy to center a div, text, or image in just three lines of code. </p>
<p>Check the snippets below for examples. </p>
<h3 id="heading-how-to-center-text-with-flexbox">How to center text with Flexbox</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I'm a Camper, and I'm vertically centered<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>; 
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss5b-1.png" alt="ss5b-1" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-an-image-with-flexbox">How to center an image with Flexbox</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"freecodecamp.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"centered"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>; 
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss6b.png" alt="ss6b" width="600" height="400" loading="lazy"></p>
<p>We took care of the vertical alignment in just two lines of code. To make the image and text horizontally centered, add in justify-content: center.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I'm a Camper, I'm now vertically and horizontally centered<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"freecodecamp.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"centered"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
}
</code></pre>
<p>The text now looks like this:
<img src="https://www.freecodecamp.org/news/content/images/2021/08/ss7bb.png" alt="ss7bb" width="600" height="400" loading="lazy"></p>
<p>And the image like this: <img src="https://www.freecodecamp.org/news/content/images/2021/08/ss11bb.png" alt="ss11bb" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-center-an-element-with-css-grid">How to Center an Element with CSS Grid</h2>
<p>With Flexbox, it is pretty easy to center anything, right? But with CSS Grid, it is really easy to center anything, because two lines of code are enough to do it for you. </p>
<h3 id="heading-how-to-center-text-with-css-grid">How to center text with CSS Grid</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I'm a Camper, and I'm vertically centered<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss8bb.png" alt="ss8bb" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-an-image-with-css-grid">How to center an Image with CSS Grid</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"centered-element"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"freecodecamp.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"centered"</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
}
</code></pre>
<p>The above examples takes care of vertical centering for you. To get the text and image centered horizontally too, replace the align items with <code>place items</code> – a combination of both <code>align-items</code> and <code>justify-content</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">display</span>: grid;
    <span class="hljs-attribute">place-items</span>: center;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">600px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
}
</code></pre>
<p>The text now looks like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss7bb-1.png" alt="ss7bb-1" width="600" height="400" loading="lazy"></p>
<p>And the image like this:
<img src="https://www.freecodecamp.org/news/content/images/2021/08/ss11bb-1.png" alt="ss11bb-1" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-center-a-standalone-div-text-or-image-in-css">How to Center a Standalone Div, Text, or Image in CSS</h2>
<p>The three methods above let you center a div, text, or image in a container. You can also center a standalone div, text, or image. </p>
<p>Let's see how to do that now.</p>
<h3 id="heading-how-to-center-a-standalone-div-in-css">How to center a standalone div in CSS</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">div</span><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">300px</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">300px</span>;
    <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#006100</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
  }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss12bb.png" alt="ss12bb" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-standalone-text-in-css">How to center standalone text in CSS</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>I'm a Camper, and I'm centered<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
</code></pre>
<pre><code class="lang-css">     <span class="hljs-selector-tag">p</span> {
         <span class="hljs-attribute">text-align</span>: center;
     }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss13bb.png" alt="ss13bb" width="600" height="400" loading="lazy"></p>
<h3 id="heading-how-to-center-a-standalone-image-in-css">How to center a standalone image in CSS</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"freecodecamp.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"centered"</span> /&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">img</span> {
      <span class="hljs-attribute">display</span>: block;
      <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span> auto;
 }
 <span class="hljs-comment">/* Applies a display of block, a margin 0f 0 at the top and bootom, 
 and auto on the left and right */</span>
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/ss14bb.png" alt="ss14bb" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I hope this tutorial gives you enough knowledge about vertical alignment and how to center elements in CSS so it's less of a hassle for you in your next project. </p>
<p>Thank you for reading, and keep coding.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn CSS Flexbox in This Crash Course ]]>
                </title>
                <description>
                    <![CDATA[ Understanding CSS Flexbox is super helpful if you want to make your websites responsive. Flexbox is a powerful responsive web design tool that's built right into CSS itself. And we just published a CSS Flexbox crash course on the freeCodeCamp.org You... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-css-flexbox/</link>
                <guid isPermaLink="false">66b20418a8b92c932923648a</guid>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Thu, 22 Jul 2021 13:58:50 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/07/cssflexbox.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Understanding CSS Flexbox is super helpful if you want to make your websites responsive.</p>
<p>Flexbox is a powerful responsive web design tool that's built right into CSS itself.</p>
<p>And we just published a CSS Flexbox crash course on the freeCodeCamp.org YouTube channel. </p>
<p>James Maxwell created this course. Not only did he create the course but he also created some amazing PDF cheat sheets to go along with it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/image-70.png" alt="Image" width="600" height="400" loading="lazy">
<em>Flexbox Cheat Sheets</em></p>
<p>The flex layout model allows responsive elements within a container to be automatically arranged depending upon the size of the screen.</p>
<p>You will learn about properties such as display, flex-direction, flex-wrap, flex-flow, justify-content, align-items, align-content, and more.</p>
<p>You can watch the full course below or on <a target="_blank" href="https://youtu.be/tXIhdp5R7sc">the freeCodeCamp.org YouTube channel</a> (35-minute watch).</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/tXIhdp5R7sc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-transcript">Transcript</h2>
<p>(autogenerated)</p>
<p>Understanding CSS Flexbox is important if you want to make responsive websites, James Maxwell created this course, along with some amazing PDF cheat sheets to go along with it.</p>
<p>Flexbox is going to change your perspective about web designing.</p>
<p>And again, for the power of course, I have created two beautiful PDF cheat sheets, which you can download.</p>
<p>These cheat sheets have got every single property that we're about to learn now.</p>
<p>One is exclusive for the parent container properties, and the others exclusive for the child properties.</p>
<p>You can use this cheat sheet for your future reference, I highly encourage everyone to follow the video now, and then later use the cheat sheets.</p>
<p>So let's dive into the concept of Flexbox.</p>
<p>Without any further delay, we are going to create a separate file for this learning purpose so that you can refer the file along with the cheat sheets in the future.</p>
<p>Let's quickly set up a head Sumo file using the Emmet function.</p>
<p>Now, I'm going to teach you guys another embed function to create a container and the children inside it.</p>
<p>So we need a div tag with a class container.</p>
<p>And then inside a greater than symbol to create a few children inside the container.</p>
<p>Let's give the Child Element a class called items.</p>
<p>So again, we'll have to enter a dart and just type items.</p>
<p>And we also want every child element to have a unique number to it.</p>
<p>So insert a hyphen, then insert $1 symbol times five.</p>
<p>This Emmet function will create a container with five items numbered within it.</p>
<p>We also want the items to have one unified Alias Name to them.</p>
<p>And we're going to call it as item.</p>
<p>So again, insert a dart and just type item.</p>
<p>Now hit enter.</p>
<p>How simple was that? This might look a little intimidating at the beginning.</p>
<p>But once you get used to it out of practice, you won't be able to create head Sumo containers without these beautiful image functions.</p>
<p>To learn more about these mn functions, you can visit Doc's dot me.io.</p>
<p>Now before moving to our CSS file, we'll have to fill in the numbers inside a div tag.</p>
<p>Let's quickly create a CSS file and link to the HTML file.</p>
<p>Let's begin with the basic reset using the universal selector.</p>
<p>So we're going to set the margin to zero padding to zero and box sizing border box.</p>
<p>Next, we're going to style the container and the child elements to implement the Flexbox properties.</p>
<p>So we're going to target the container now.</p>
<p>And give it a background color of hash Ca Ca NCAA, which is a light gray color.</p>
<p>And then give it a padding of 10 pixels.</p>
<p>Then a margin of 50 pixels.</p>
<p>Next, we're going to talk at the item selector.</p>
<p>And we're gonna give them a background color of hash, ff 0037, which is a nice red color.</p>
<p>And then for the font and so the item, they're gonna give them a white color.</p>
<p>Font Size of 35 pixels, padding of 20 pixels and a margin of 10 pixels.</p>
<p>If you see here, we haven't implemented any Flexbox yet, but we have a gray color container and red color items inside the container.</p>
<p>The items could be anything in a real website.</p>
<p>It could be the navbar of the website, or few majors paragraphs or whatever.</p>
<p>This video is all about the Flexbox container properties.</p>
<p>To enable Flexbox we'll have to set the display property to flex inside the container.</p>
<p>So let's set the display property to flex inside a container.</p>
<p>You can already see the magic Flexbox has produced a work a lot as you can see, to create this kind of layout using the float property position property and the margin properties, it would have been a tedious process, I would never take that risk personally, just by setting the display property to flex in the parent container, the child elements have become the flex items.</p>
<p>Now, let's talk about the flex direction property.</p>
<p>The flex direction property is used to find the direction of the flex items within the container.</p>
<p>By default, the flex direction is set a row.</p>
<p>When the flex direction is set a row, you see nothing happens.</p>
<p>Apart from row, there are a few other direction values that will change the direction of the children inside the container.</p>
<p>Let's see them one by one.</p>
<p>When we change the flex direction column, you can see the children items are arranged vertically in a column.</p>
<p>That's the superpower Flexbox.</p>
<p>By setting the direction to column, we have changed the axis itself.</p>
<p>There are two different axes according to Flexbox, the main axis and the cross axis, the axis differs for different directions.</p>
<p>For the flex direction set row, the main axis would be the x axis.</p>
<p>For the flex direction set of column, the main axis would be the y axis.</p>
<p>This concept is nothing related to the Flexbox, our web development, this basic math, to invert the direction of the flex items in either column or row, we can use the column reverse or the row voice values.</p>
<p>When the direction is set a column reverse.</p>
<p>You can see the direction of the items are inverted in the y axis.</p>
<p>So the main axis here goes from the bottom to top there before it was going from the top to bottom.</p>
<p>And of course, the numbers are in the reverse order fires in the top and one isn't the bottom.</p>
<p>The same rule applies for reverse, you can pick the right word that one would do.</p>
<p>So when I said the flex reaction to reverse? Exactly, it stacks the items in the reverse order.</p>
<p>Here, the main axes most from right to left.</p>
<p>And the numbers are also in the reverse order, you should always be aware of the main axis.</p>
<p>That's really important.</p>
<p>Since we've experimented all the possible values for flex reaction property, let's set it back to row which is the default value.</p>
<p>We haven't explored much about Flexbox yet, but I'm sure you could understand how much Flexbox is going to help us in the making of a responsive design.</p>
<p>Probably when designing for a smaller screen, we can simply set the flex direction to column, which will stack the items one on top of the other.</p>
<p>So that's all about the flex direction.</p>
<p>Next up, I want to discuss about the justify content property.</p>
<p>So remember that the justify content properly defines how the flex items should be stacked along the main axis.</p>
<p>Let's start with the center value here.</p>
<p>Now automatically, all the flex items are stacked in the center here.</p>
<p>Let me zoom in a little bit so you can see things clearly.</p>
<p>Right, you can always use the dev tools to inspect the elements.</p>
<p>The browser has understood that this div tag is using Flexbox.</p>
<p>When you hover over the justify content property, you can see how beautifully Flexbox had calculated the distances and align the items in the center.</p>
<p>Just imagine if we didn't have Flexbox.</p>
<p>To create this very simple layout.</p>
<p>Well, we should have used a float property that would have been a real nightmare for us.</p>
<p>So the center value aligns the flex items right in the center of the container.</p>
<p>But it does not do anything with the space in between the items.</p>
<p>The space between the items is because of the margin value we give for item selector.</p>
<p>So if the comment is value, you can see a flex items are tightly packed.</p>
<p>Let's quickly uncomment this margin and experiment the next value which is space between so let's change the justify content space between then we said the justify content space between you can see that the space between our flex items are evenly distributed.</p>
<p>We didn't have to specify any number here, but Flexbox automatically calculates the distance and distribute the items according to the space available.</p>
<p>The best part here is the other side.</p>
<p>Have a browser, the space between items also adjust.</p>
<p>That makes it really handy to create a responsive layout.</p>
<p>Let's now come on the margin property inside the item selector again, because we're going to explore another value which is similar to the space between called the space around changing the justify content space around you can see the space around value had created equal amount of space on both the left and the right side of the flex items.</p>
<p>The space between these two items is twice the amount of space on the left side of this item.</p>
<p>Next up, we're going to see the space evenly value.</p>
<p>So changing the ship icon or space evenly.</p>
<p>When I started using the flex box, I initially didn't understand the difference between these values, that's totally normal.</p>
<p>You'll start understanding these values once you start using them in your projects.</p>
<p>So setting the value to space evenly, you can see that the space between the flex items is evenly distributed on both sides.</p>
<p>The space between flex item one and flex item two is the same as the rest.</p>
<p>So while space II will ensure that the space between the items is always the same on both the sides, the space around nature that the space around each item is the same on the left and the right side.</p>
<p>Definitely not a big difference, but the usages differ completely.</p>
<p>There are two more values for the justify content property, the flex start and the flex end values and the justify content they serve flex start.</p>
<p>Well, it is the default value.</p>
<p>Let's uncomment the margin value to ensure that yes, it is the default value.</p>
<p>Now, if he said the justify content, a flex end.</p>
<p>Here a very complete attention.</p>
<p>People often confused between raw reverse and the flex in values.</p>
<p>Reverse will invert the order of the flex items.</p>
<p>But the flex in value when you move the flex items to the end of the container, maintaining the margin if provided.</p>
<p>Alright, the last property we're going to discuss in this video is the Align items.</p>
<p>To justify content property aligns the flex items along the main axis, but the Align items property aligns the flex items along the cross axis.</p>
<p>In order to make the Align items property work, we're now going to make one of the flex items bigger than the rest.</p>
<p>Because every flex item is having an unified hide.</p>
<p>So it will be difficult to demonstrate the Align items property to kind of pick the third item and set its height to 150 pixels.</p>
<p>Let's also change the justify content center.</p>
<p>And here it is.</p>
<p>I'm just noticing an error with my nomenclature.</p>
<p>I've included numbers for items, which should have been four item that's totally fine.</p>
<p>Here, you can see that all of flex items are now having a height of 150 pixels and not just the flex item three.</p>
<p>That's not a bug, but it happens because the default value for our line items is scratch.</p>
<p>When the line item is to stretch, this is what happens.</p>
<p>So let's also add the Align items to center.</p>
<p>All right, we can visualize how align items property align or flex items along the cross axis.</p>
<p>Here we have one flex item that is bigger than the rest.</p>
<p>And with the Align items property service center, we center the smaller flex items relative to the bigger one in the vertical fashion.</p>
<p>If we now set the Align items to flex start all the items will start at the top along the top of the bigger flex item.</p>
<p>The opposite will happen if we say the Align items to flex end.</p>
<p>So the flex items align equally at the bottom.</p>
<p>So far we saw center flex start flexing and the stretch values for the Align items property.</p>
<p>The stretch value Prices stretch the height of all flex items to match the height of the tallest flex item.</p>
<p>There is one last value for the Align items property, it is called the baseline.</p>
<p>It lies the baseline value will first have to increase the font size of one of the item.</p>
<p>So let's select item number four, and increase its font size to sound pixels.</p>
<p>If we now set the Align items to baseline, you can see that it aligns all the flex items along the text inside the item number four on an imaginary line.</p>
<p>I'm not going to reset a line items center and get rid of items number four, and items.</p>
<p>Number three selectors here.</p>
<p>All right, we're coming to the end of this video.</p>
<p>So flex direction, justify content, and the Align items are the most important and the frequently use properties.</p>
<p>Of course, there are a few other properties, but we will see them in another video.</p>
<p>Before we end this video, I want to answer to one of the highest rated question, what will happen to justify content and the Align items property and the flex direction instead of column? Well, let's check that out.</p>
<p>Great.</p>
<p>If you notice, the main axis had changed now.</p>
<p>It is no longer going from left to right.</p>
<p>But it is going from top to bottom.</p>
<p>Everything is fine.</p>
<p>But why is that the items are aligned to the center yet? Well, that's due to align items, they said the center and the flex direction the set of column.</p>
<p>When the flex direction is set a column, the main axis would be the y axis and the cross axis would be the x axis.</p>
<p>We know that the Align items property affects the cross axis.</p>
<p>And that's why our items are aligned at the center vertically.</p>
<p>So if we now set the Align items to flex end, and you can see that the items are aligned at the end of the container vertically.</p>
<p>The opposite of this will happen if we said the Align items to flex start.</p>
<p>And yes, the items are stacked at the beginning of the container.</p>
<p>So I would again emphasize you guys to always keep a track of the main axis and the cross axis in order to use justify content and align items in the right way.</p>
<p>Now for your better understanding.</p>
<p>I'll also experiment with the justify content when the flexor action is a call.</p>
<p>For that, we should first set a height value for the container.</p>
<p>So maybe let's set it to 1400 pixels.</p>
<p>And then I'll decrease the size of my viewport.</p>
<p>Now that said justify content space between here if I hover over the justify content on my dev tools, you can see that the space between the items are distributed just as we saw earlier, but in the vertical direction.</p>
<p>All right, let's end this video here.</p>
<p>I know I'm leaving most of you with a skeptical mind.</p>
<p>But that's totally normal for any beginner.</p>
<p>I felt the same when I learned Flexbox for the first time.</p>
<p>And that's why I made those beautiful cheat sheets for the reference purpose.</p>
<p>I feel it would have been better if someone gave me those cheat sheets when I started learning Flexbox you can now rewatch this video along with the cheat sheet so that you get a better clarity about these concepts.</p>
<p>Let's quickly set the flex direction row, remove the height and set justify content in align items center and end this video.</p>
<p>Great.</p>
<p>Let's meet back in the next lecture to learn more about the Flexbox concepts.</p>
<p>The last lecture, we learned three important Flexbox container properties.</p>
<p>There are a few more but we'll see them later.</p>
<p>Now in this video, let's learn about the Flexbox child properties.</p>
<p>So this is where we left in our last video.</p>
<p>The first property we're going to learn in this lecture is the Align self property.</p>
<p>The lens of property is similar to the Align items property.</p>
<p>With the help of align items property, we were able to collectively change the alignment of a flex item Along the cross axis, but the Allen self property will align one single flex item along the cross axis.</p>
<p>And it can also override the Align items property.</p>
<p>I know it sounds like gobbledygook, let's see them in action to understand how it works.</p>
<p>to experiment the outlines of property, let's again create the item three selector and give it a height of 150 pixels.</p>
<p>You're going to use item three as a reference point.</p>
<p>So let's try applying a lens off to item number four.</p>
<p>Right after item number three, you're going to create item number four selector and creating a lens of property here.</p>
<p>Let's set this to flex start.</p>
<p>Well, you can see that when the item number four is aligned at the start of the flex container, and all of the flex items are aligned to the center of item three along the cross axis, align self property accepts every single value that align items property accepts.</p>
<p>But as I told you earlier, we use a lens of property only to align an individual item.</p>
<p>Now, let's change this to flex and and see what happens.</p>
<p>So the item had moved to the bottom of the flex container.</p>
<p>Now, when Allen's office said a stretch.</p>
<p>Well, the item stretches to match the height of the tallest item, which is item three in our case.</p>
<p>Now, I'll leave this to you guys.</p>
<p>Go ahead and experiment the other possible values like center space between space evenly spaced around and try to analyze the use cases.</p>
<p>Next up, we're going to play with the order of a flex items.</p>
<p>The auto property is used to change the portion of flex items within the container to experiment this property to going to create selectors for all of flex items and change the order the initial value of order zero.</p>
<p>So according to Flexbox, the flex item one is in the zero portion.</p>
<p>Let's set order property to every flex item and change the potions.</p>
<p>So we're going to move item one to push in three.</p>
<p>Then item two, to potion for item three, to question zero item for position one.</p>
<p>item five to question two.</p>
<p>So after saving the file, you can see our items are relocated.</p>
<p>want you guys to understand that these values are give here are just experimental values.</p>
<p>You can go ahead and arrange the items as you wish.</p>
<p>But again, I would encourage everyone to follow the order I'm giving here so that we continue on the same track.</p>
<p>If you see here, one is a third question to set forth version three is add zero to question four is that first question and phi is that second portion.</p>
<p>The auto property will be handy for us to relocate the portion of the elements when it comes to responsive design.</p>
<p>You can see some people using negative values to change the order.</p>
<p>But I never encourage anyone to use negative values that will confuse us when we look at our code in the future.</p>
<p>That's all about the auto property.</p>
<p>We're now going to see the last three properties associated with the flex box child items.</p>
<p>The flex grow flex ring and the flex basis and remove the auto properties from all of flex items.</p>
<p>The first going to see the flex grow property now.</p>
<p>The flex group property enables a flex item to grow.</p>
<p>To grow a flex item.</p>
<p>All we do is specify an integer, just a number like how we assigned to the auto property.</p>
<p>to experiment this property.</p>
<p>Let's apply generally in the item selector.</p>
<p>So I'm going to create a flex group property and set it to one.</p>
<p>Well, all of flex items have become larger in size.</p>
<p>So here all the flex items are occupying the empty space that they can fit into the container.</p>
<p>In other words, the occupying the maximum space available inside the container we can visualize is better if we again come in the margin property.</p>
<p>You can see they're touching each other now, and occupying all the space that they can, that's about the flex grow property that we uncover this margin property now.</p>
<p>So even if you change this one 200, they're not going to get any bigger than this.</p>
<p>That's because the value only matters in relation to the rest.</p>
<p>Let's reset this value to one and try to understand how the value matters.</p>
<p>In relation with the other flex grow values.</p>
<p>Let's add a flex group property to item four and give it three.</p>
<p>So here, item number four is three times bigger than the rest of the flex items.</p>
<p>By this I'm sure you can understand how the flex group property works relatively.</p>
<p>When I change this three to five, it's going to become five times bigger than the other flex items.</p>
<p>That's all about the flex group property.</p>
<p>Let's remove the flex group property from item number four and discuss about a short end property.</p>
<p>So the last few properties we are learning have a shortened property to them, we can directly call them using the flex keyword.</p>
<p>So with the flex keyword, we can declare three different values.</p>
<p>The first value will be for a flex grow property, the second will be for flex ring.</p>
<p>And the last will be for flex basis, then we simply give one is the first value, it will automatically understand that we're declaring the flex grow value.</p>
<p>So if remember the grow keyword from here, every flex item is still occupying the maximum space.</p>
<p>This method is going to be extremely handy when it comes to real world projects.</p>
<p>And in most cases, we'll be using the shorthand property in a project.</p>
<p>Maybe we want one of our flex items to grow larger than the rest.</p>
<p>For example, let's try growing the last item.</p>
<p>Now setting flex five to item number five, you can see that it is occupying the maximum space and the rest are relatively occupying the available space.</p>
<p>This is all about the flex grow property.</p>
<p>Next up, we're going to see the flex basis property.</p>
<p>Flex basis property will set the width of a flex item.</p>
<p>Instead of using the width property, we can use the flex basis using the flex basis property or the width property would mean the same.</p>
<p>That's always a personal choice.</p>
<p>But in my opinion, I would say it is always good to practice to use the flex basis property so that we'll be able to differentiate the flex item and the nominal item.</p>
<p>Now for our example, I'm going to change this to flex basis and said this is 75 percentage.</p>
<p>When we're using the flex basis property, we should declare a percentage based value or a pixel based value.</p>
<p>Now, the item number five is occupying 75 percentage of the container and the rest are altered to occupy the remaining 25 percentage space by setting the flex basis to auto in the background.</p>
<p>Do not worry if you're not able to understand the difference between these properties.</p>
<p>You're going to use them a lot in our course.</p>
<p>So you'll eventually understand them out of practice.</p>
<p>The very last property we're going to see in this video is flex shrink.</p>
<p>So to show you guys what the fracturing property does, let me change this percentage value to pixel based value.</p>
<p>Maybe let me change this to 700 pixels.</p>
<p>Right.</p>
<p>Let me also minimize my browser window to demonstrate this property.</p>
<p>Now, if I increase the viewport width, just see what happens.</p>
<p>So you can see that our item number five shrinks at a certain breakpoint.</p>
<p>In spite of setting its flex basis to 700 pixels, it shrinks at a certain point.</p>
<p>To avoid this, we declare the flex string property and set it to zero.</p>
<p>The only two values to the flex string property one and zero.</p>
<p>So it works as a binary property.</p>
<p>By default it is set to one which means it will shrink the flex item at a point.</p>
<p>Let's try setting the flex string property to zero and see what happens.</p>
<p>But before that, let me expand my browser window size Going to my text editor.</p>
<p>I'm going to set a flat string property to item number five and set it to zero.</p>
<p>Now, if I try to decrease my browser window size Well, you can see that after setting flexion to zero, no matter how much size we take off from the viewport, the item number five is not shrinking.</p>
<p>But the rest of the items are overflowing the viewport.</p>
<p>In most case, people ignore to understand that they using the flex ring property.</p>
<p>In real time we use a flex keyword where we can consecutively declare all three properties flex grow flex ring, and the flex basis that we want to target the flex basis, aka the width property to set the flex items with.</p>
<p>And that's how we'll be implementing in our course too.</p>
<p>After watching this video, I highly encourage everyone to open up the cheat sheet and practice until this point.</p>
<p>In the next video, we're going to learn the rest of the flex container properties and in this section.</p>
<p>Before we end this section, I would like to teach you guys how to handle a lot of flex items into the flex container.</p>
<p>So right now we have five flex items.</p>
<p>Let's simply add another five flex items to our container and receive the class names.</p>
<p>So you can see that all these flex items are closely packed to fit into the container, and some are overflowing the flex container at zoom a browser to 150 percent is for the demonstration purpose.</p>
<p>If you don't find these items overflowing, simply zoom your browser window as I've said.</p>
<p>Now coming back to the point, we have this one last video for this section.</p>
<p>Because they've got a solution if you find a flex items getting cramped up like this.</p>
<p>So we can use the flex wrap property to overcome this issue.</p>
<p>The default value for flex wrap is no wrap.</p>
<p>And that's why our flex items are overflowing the container.</p>
<p>But if we create a flex wrap property into the container selector and set it a wrap.</p>
<p>Then this will create a new line like this to fit all the flex items inside the container.</p>
<p>In case we are a selector for Item Number 10 and said the flex to one.</p>
<p>You can see Item Number 10 is occupying its maximum space in the line.</p>
<p>Now if you shrink the browser size, then the flex wrap property will wrap the flex items more and more to ensure that all the flex items fit into the container.</p>
<p>And once again, this is going to be extremely useful for the responsive design, then we have less amount of space in the screen.</p>
<p>Now let me increase the height of the container here and show you guys what will happen.</p>
<p>And we let's set this to 600 pixels and see what happens.</p>
<p>So here we still have two rows.</p>
<p>But why do we have this empty space in between.</p>
<p>That's because of the Align content property which we haven't discussed yet.</p>
<p>That's again a flex container property.</p>
<p>So let's create it align content property into the container selector and set it to flex start.</p>
<p>Now as you can see, every row in a flex container is at the top of the container.</p>
<p>Therefore the Align content property aligns the row in the cross axis into the container.</p>
<p>Again, we can use the same values for the alencon in property as we use for the island items and the islands of property.</p>
<p>Here, I want you guys to pause the video and analyze the difference between the Align items align itself in the LM content properties.</p>
<p>Now let's set the LM content center.</p>
<p>So as you can see, a rows are aligned at the center of the container.</p>
<p>We can also change the flex end.</p>
<p>And yes, the rows are at the end of the container.</p>
<p>Then let's see the space around On space between and finally the space evenly.</p>
<p>So the old walk in the same logic, as you see, these properties will take some time for you to memorize.</p>
<p>But you don't have to really worry about it because From now on, the only going to use the Flexbox in our main project.</p>
<p>Kudos to everyone.</p>
<p>We have mastered the concept of Flexbox.</p>
<p>Let's not waste any more time.</p>
<p>We have got a beautiful app to be constructed inside our website.</p>
<p>So it mitigates in the next section, where we'll be reconstructing a navbar and the hero section, and then we'll move on to our app. </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Center Anything in CSS Using Flexbox and Grid ✨ ]]>
                </title>
                <description>
                    <![CDATA[ Today I'm gonna show you how you can center and align your content with CSS. Along the way, we'll look at various alignment techniques. So, let's get started! 🥇 Table of Contents -> How to Use Flexbox to center anything horizontally center anything... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-center-objects-using-css/</link>
                <guid isPermaLink="false">66b20957f31aa965000e5889</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ flexbox ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joy Shaheb ]]>
                </dc:creator>
                <pubDate>Fri, 11 Jun 2021 20:40:17 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/06/FCC--center.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Today I'm gonna show you how you can <strong>center and align</strong> your content with CSS. Along the way, we'll look at various <strong>alignment techniques</strong>. So, let's get started! 🥇</p>
<h2 id="heading-table-of-contents-gt">Table of Contents -&gt;</h2>
<ul>
<li>How to Use <strong>Flexbox</strong> to<ul>
<li><a class="post-section-overview" href="#heading-how-to-center-anything-horizontally-using-flexbox">center anything horizontally</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-anything-vertically-using-flexbox">center anything vertically</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-a-div-horizontally-amp-vertically-using-flexbox">center both horizontally &amp; Vertically</a></li>
</ul>
</li>
<li>How to Use <strong>Grid</strong> to <ul>
<li><a class="post-section-overview" href="#heading-how-to-center-anything-horizontally-using-css-grid">center anything horizontally</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-anything-vertically-using-css-grid">center anything vertically</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-a-div-horizontally-amp-vertically-using-css-grid">center both horizontally &amp; Vertically</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-css-position-property-to-center-anything">The Transform &amp; position property</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-margin-property-to-center-anything">The Margin Property</a></li>
<li><a class="post-section-overview" href="#heading-additional-resources"><strong>Additional resources</strong></a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-73.png" alt="Image" width="600" height="400" loading="lazy">
<em>Methods</em></p>
<h2 id="heading-you-can-watch-this-tutorial-on-youtube-as-well-if-you-like">You can watch this tutorial on YouTube as well if you like:</h2>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/RTEzXS_CT5w" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-but-wait-a-minute">But.... Wait A Minute!</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-35--3-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>First of all, let's understand:</p>
<ul>
<li>Main Axis </li>
<li>Cross Axis</li>
</ul>
<h2 id="heading-what-is-the-main-axis-in-css">What is the Main Axis in CSS?</h2>
<p>You can also call it the:</p>
<ul>
<li><strong>X-Axis</strong> </li>
<li>Main Axis </li>
<li>Horizontal Line </li>
</ul>
<p>The line from <strong>left</strong> to <strong>right</strong> is the Main-Axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-71.png" alt="Image" width="600" height="400" loading="lazy">
<em>Main Axis</em></p>
<h2 id="heading-what-is-the-cross-axis-in-css">What is the Cross Axis in CSS?</h2>
<p>You can also call it the:</p>
<ul>
<li><strong>Y-Axis</strong> </li>
<li>Cross Axis</li>
<li>Vertical Line </li>
</ul>
<p>The line from <strong>top</strong> to <strong>bottom</strong> is the Cross-Axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-72.png" alt="Image" width="600" height="400" loading="lazy">
<em>Cross Axis</em></p>
<h1 id="heading-project-setup">Project Setup</h1>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-54.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To experiment with all the properties and values, write the following code in your code editor.</p>
<h3 id="heading-html">HTML</h3>
<p>Write this code inside the body tag:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"container"</span>&gt;</span>

   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"box-1"</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="heading-css">CSS</h3>
<p>Clear the <strong>default</strong> browser styles so that we can work more accurately:</p>
<pre><code class="lang-css">*{
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0px</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">0px</span>;
  <span class="hljs-attribute">box-sizing</span>: border-box;
}
</code></pre>
<p>Select the <strong>.container</strong> class and set it to 100vh. Otherwise, we can't see our result on the <strong>Vertical Axis</strong>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
}
</code></pre>
<p>Style the <strong>.box-1</strong> class like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
   <span class="hljs-attribute">width</span>: <span class="hljs-number">120px</span>;
   <span class="hljs-attribute">height</span>: <span class="hljs-number">120px</span>;
   <span class="hljs-attribute">background-color</span>: skyblue;
   <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid black;
}
</code></pre>
<p>We're all set, now let's start coding!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-3--5-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-use-flexbox-to-center-anything">How to use Flexbox to center anything</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Thumbnail-hashnode.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can use Flexbox to align our content <code>div</code> both along the X and Y Axis. To do that, we need to write the <code>display: flex;</code> property inside the <code>.container</code> class:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">display</span>: flex;

   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
}
</code></pre>
<p>We'll experiment with these 2 properties:</p>
<ul>
<li><code>justify-content</code></li>
<li><code>align-items</code></li>
</ul>
<h2 id="heading-how-to-center-anything-horizontally-using-flexbox">How to center anything horizontally using Flexbox</h2>
<p>We can use the <strong>justify-content</strong> property to do this using these values 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Justify-content-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>values of flexbox justify-content property</strong></em></p>
<p>To experiment with the values, write the following code👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">display</span>: flex;
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

 <span class="hljs-comment">/* Change values to  👇 experiment*/</span>
   <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>The result will look like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-6--2-.png" alt="Image" width="600" height="400" loading="lazy">
<em>result of justify-content flexbox</em></p>
<h2 id="heading-how-to-center-anything-vertically-using-flexbox">How to center anything vertically using Flexbox</h2>
<p>We can use the <strong><code>align-items</code></strong> property to do this using these values 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/align-items-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>values of Flexbox align-items property</strong></em></p>
<p>To experiment with the values, write the following code👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: flex;

 <span class="hljs-comment">/* Change values 👇 to experiment*/</span>
   <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<p>The result looks like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-7--4-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Result of align-items flexbox</em></p>
<h2 id="heading-how-to-center-a-div-horizontally-amp-vertically-using-flexbox">How to center a div horizontally &amp; vertically using Flexbox</h2>
<p>Here, we can combine both the <strong><code>justify-content</code></strong> and <strong><code>align-items</code></strong> properties to align a div both horizontally and vertically.</p>
<p>Write the following codes👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: flex;

<span class="hljs-comment">/* Change values 👇 to experiment*/</span>
   <span class="hljs-attribute">align-items</span>: center;
   <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>The result looks like this 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-8--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Centering a div Horizontally &amp; vertically</em></p>
<p>You can check out this <a target="_blank" href="https://www.freecodecamp.org/news/css-flexbox-tutorial-with-cheatsheet/">cheatsheet</a> to learn more about various Flexbox properties.</p>
<h2 id="heading-how-to-use-css-grid-to-center-anything">How to use CSS Grid to center anything</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-70.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can use <strong>grid</strong> to align our content <code>div</code> both along the X and Y Axis. To do that, we need to write the <code>display: grid;</code> property inside the <code>.container</code> class:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">display</span>: grid;

   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
}
</code></pre>
<p>We'll experiment with these 2 properties:</p>
<ul>
<li><code>justify-content</code></li>
<li><code>align-content</code></li>
</ul>
<p><strong>Alternatively</strong>, you can use these 2 properties:</p>
<ul>
<li><code>justify-items</code></li>
<li><code>align-items</code> </li>
</ul>
<h2 id="heading-how-to-center-anything-horizontally-using-css-grid">How to center anything horizontally using CSS Grid</h2>
<p>We can use the <strong><code>justify-content</code></strong> property to do this using these values 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/justify-content-1--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>values of Grid justify-content property</strong></em></p>
<p>Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: grid;

  <span class="hljs-comment">/* Change  values   👇 to experiment*/</span>
   <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>The result looks like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-6--2--1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>result of justify-content grid</strong></em></p>
<h2 id="heading-how-to-center-anything-vertically-using-css-grid">How to center anything vertically using CSS Grid</h2>
<p>We can use the <strong><code>align-content</code></strong> property to do this using these values 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/align-content-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Values of CSS grid align-content property</em></p>
<p>Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: grid;

  <span class="hljs-comment">/*  Change values 👇 to experiment*/</span>
   <span class="hljs-attribute">align-content</span>: center;
}
</code></pre>
<p>The result will look like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-7--4--1.png" alt="Image" width="600" height="400" loading="lazy">
<em>result of align-content grid</em></p>
<h2 id="heading-how-to-center-a-div-horizontally-amp-vertically-using-css-grid">How to center a div horizontally &amp; vertically using CSS Grid</h2>
<p>Here, we can combine both the <strong><code>justify-content</code></strong> and <strong><code>align-content</code></strong> properties to align a div both horizontally and vertically.</p>
<p>Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: grid;

<span class="hljs-comment">/* Change  values  👇 to experiment*/</span>
   <span class="hljs-attribute">align-content</span>: center;
   <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<p>The result looks like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-8--1--1.png" alt="Image" width="600" height="400" loading="lazy">
<em>Centering a div Horizontally &amp; vertically with Grid</em></p>
<h2 id="heading-alternative-way">Alternative way</h2>
<p>You can also use the <strong><code>justify-items</code></strong> and <strong><code>align-items</code></strong> properties to duplicate the same results:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: grid;

<span class="hljs-comment">/* Change  values  👇 to experiment*/</span>
   <span class="hljs-attribute">align-items</span>: center;
   <span class="hljs-attribute">justify-items</span>: center;
}
</code></pre>
<h2 id="heading-the-place-content-property-in-css-grid">The place-content Property in CSS Grid</h2>
<p>This is the <strong>shorthand</strong> of 2 properties of CSS Grid-&gt;</p>
<ul>
<li><code>justify-content</code></li>
<li><code>align-content</code></li>
</ul>
<p>Follow along 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">display</span>: grid;

   <span class="hljs-attribute">place-content</span>: center;
}
</code></pre>
<p>We get the same result 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-8--1--2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Centering a div Horizontally &amp; vertically</em></p>
<p>Check out this <a target="_blank" href="https://www.freecodecamp.org/news/css-grid-tutorial-with-cheatsheet">cheatsheet</a> to find out the difference between various Grid properties.</p>
<h2 id="heading-take-a-break">Take a break!</h2>
<p>So far so good – take a break.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-67--1-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-use-the-css-position-property-to-center-anything">How to use the CSS Position Property to center anything</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-12-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This is a combination of these properties -&gt;</p>
<ul>
<li><code>position</code></li>
<li><code>top, left</code></li>
<li><code>transform, translate</code> </li>
</ul>
<p>Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
   <span class="hljs-attribute">position</span>: relative;
}
</code></pre>
<p>Along with this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
   <span class="hljs-attribute">position</span>: absolute;

   <span class="hljs-attribute">width</span>: <span class="hljs-number">120px</span>;
   <span class="hljs-attribute">height</span>: <span class="hljs-number">120px</span>;
   <span class="hljs-attribute">background-color</span>: skyblue;
   <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid black;
}
</code></pre>
<h2 id="heading-first-understand-the-center-point-of-a-div">First... Understand the center point of a div</h2>
<p>By default, this is the center point of a div 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-9.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Default Center point of a div</strong></em></p>
<p>That's why we see this odd behavior 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-8--2-.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Box is not at exact center</strong></em></p>
<p>Notice that the box is not at the <strong>exact</strong> center in the image above. 👆</p>
<p>By writing this line 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">transform</span>: <span class="hljs-selector-tag">translate</span>(<span class="hljs-selector-tag">-50</span>%,<span class="hljs-selector-tag">-50</span>%);
</code></pre>
<p>We fix the problem 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-10--2-.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>New Center point of our div</strong></em></p>
<p>And we get this result 👇 </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-11--1-.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Box is at exact center point</strong></em></p>
<h2 id="heading-what-is-the-translate-property-in-css">What is the Translate property in CSS?</h2>
<p>Translate is the shorthand of 3 properties -&gt;</p>
<ul>
<li><code>translateX</code></li>
<li><code>translateY</code></li>
<li><code>translateZ</code></li>
</ul>
<h2 id="heading-how-to-center-a-div-horizontally-using-css-position-property">How to center a div horizontally using CSS Position property</h2>
<p>We're gonna use the <code>left</code> property inside the<code>.box-</code> class. Follow along 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
<span class="hljs-comment">/* other codes are here*/</span>    

   <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
   <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>);
}
</code></pre>
<p>And we get this result 👇 </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-6--2--2.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>result of left &amp; transform property</strong></em></p>
<h2 id="heading-how-to-center-a-div-vertically-using-css-position-property">How to center a div vertically using CSS Position property</h2>
<p>We're gonna use the <code>top</code> property inside the<code>box-</code> class. Follow along 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
<span class="hljs-comment">/* Other codes are here*/</span>    

   <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
   <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(<span class="hljs-number">0</span>,-<span class="hljs-number">50%</span>);
}
</code></pre>
<p>And we get this result 👇 </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-7--4--2.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>result of top &amp; transform property</strong></em></p>
<h2 id="heading-how-to-center-a-div-horizontally-amp-vertically-using-css-position-property">How to center a div horizontally &amp; vertically using CSS position property</h2>
<p>To achieve this result, we're gonna combine these properties together -&gt;</p>
<ul>
<li><code>top, left</code></li>
<li><code>transform, translate</code></li>
</ul>
<p>Follow along 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
<span class="hljs-comment">/*Other codes are here */</span>    

   <span class="hljs-attribute">top</span>: <span class="hljs-number">50%</span>;
   <span class="hljs-attribute">left</span>: <span class="hljs-number">50%</span>;
   <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translate</span>(-<span class="hljs-number">50%</span>,-<span class="hljs-number">50%</span>);
}
</code></pre>
<p>And we get this result 👇 </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-8--1--3.png" alt="Image" width="600" height="400" loading="lazy">
<em>result of position &amp; transform property</em></p>
<h2 id="heading-how-to-use-the-margin-property-to-center-anything">How to use the margin Property to center anything</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-73--2-.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The margin property is the shorthand of 4 properties </p>
<ul>
<li><code>margin-**top**</code>, <code>margin-**bottom**</code></li>
<li><code>margin-**left**</code>, <code>margin-**right**</code></li>
</ul>
<p>Write this code to set it up 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span>{
   <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

   <span class="hljs-attribute">display</span>: flex;
}

<span class="hljs-selector-class">.box-1</span>{
   <span class="hljs-attribute">width</span>: <span class="hljs-number">120px</span>;
   <span class="hljs-attribute">height</span>: <span class="hljs-number">120px</span>;
   <span class="hljs-attribute">background-color</span>: skyblue;
   <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid black;
}
</code></pre>
<h2 id="heading-how-to-center-a-div-horizontally-using-css-margin-property">How to center a div horizontally using CSS margin property</h2>
<p>We're gonna use the <code>margin</code> property inside the <code>.box-1</code> class. Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
 //Other codes are here 

  <span class="hljs-attribute">margin</span>: <span class="hljs-number">0px</span> auto;    
}
</code></pre>
<p>The result looks like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-6--2--3.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>**result of</strong> CSS margin Property**</em></p>
<h2 id="heading-how-to-center-a-div-vertically-using-css-margin-property">How to center a div vertically using CSS margin property</h2>
<p>We're gonna use the <code>margin</code> property inside the <code>.box-1</code> class. Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
 //Other codes are here 

  <span class="hljs-attribute">margin</span>: auto <span class="hljs-number">0px</span>;    
}
</code></pre>
<p>The result looks like this 👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-7--4--3.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>**result of</strong> CSS margin property**</em></p>
<h2 id="heading-how-to-center-a-div-horizontally-amp-vertically-using-css-margin-property">How to center a div horizontally &amp; vertically using CSS margin property</h2>
<p>We're gonna use the <code>margin</code> property inside the<code>.box-</code> class. Write the following code 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
 //Other codes are here 

  <span class="hljs-attribute">margin</span>: auto auto;    
}
</code></pre>
<p>The result looks like this👇</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/06/Frame-8--1--4.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Result of CSS margin property</strong></em></p>
<h2 id="heading-additional-resources">Additional Resources</h2>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/css-flexbox-tutorial-with-cheatsheet/">Complete Flexbox Tutorial W/ CheatSheet</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/css-grid-tutorial-with-cheatsheet/">Complete CSS Grid Tutorial W/ CheatSheet</a></li>
</ul>
<h1 id="heading-credits">Credits</h1>
<ul>
<li><a target="_blank" href="https://www.flaticon.com/packs/unicorn-4">uncorns</a>, <a target="_blank" href="https://www.flaticon.com/packs/kitty-avatars-3">kitty</a></li>
<li><a target="_blank" href="https://www.freepik.com/free-vector/collection-people-enjoying-their-free-time_4931926.htm#position=7">artist</a>, <a target="_blank" href="https://www.freepik.com/free-vector/cute-cat-unicorn-play-box-cartoon-icon-illustration_12567355.htm#position=0">kat</a></li>
</ul>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Now, you can confidently <strong>align or center</strong> your content using any of these four methods in CSS.</p>
<p>Here's your <strong>medal</strong> for reading until the end ❤️</p>
<h2 id="heading-suggestions-amp-criticisms-are-highly-appreciated">Suggestions &amp; Criticisms Are Highly Appreciated ❤️</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/usxsz1lstuwry3jlly4d.png" alt="Alt Text" width="1000" height="245" loading="lazy"></p>
<p><strong>YouTube / <a target="_blank" href="https://www.youtube.com/c/JoyShaheb">Joy Shaheb</a></strong></p>
<p><strong>LinkedIn / <a target="_blank" href="https://www.linkedin.com/in/joyshaheb/">Joy Shaheb</a></strong></p>
<p><strong>Twitter / <a target="_blank" href="https://x.com/JoyShaheb">JoyShaheb</a></strong></p>
<p><strong>Instagram / <a target="_blank" href="https://www.instagram.com/joyshaheb/">JoyShaheb</a></strong></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
