<?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[ CSS Grid - 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[ CSS Grid - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 23 Jun 2026 04:39:36 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/css-grid/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Create a Masonry Layout Using HTML and CSS ]]>
                </title>
                <description>
                    <![CDATA[ A masonry layout is a grid-based design where items are arranged in a way that minimizes vertical gaps between them.  an example of a masonry layout Unlike traditional grids with fixed row heights, masonry layouts adjust the positioning of items dyn... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-create-a-mansory-layout-using-html-and-css/</link>
                <guid isPermaLink="false">66ba1be4b6a437d5f189cf85</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Fanny Nyayic ]]>
                </dc:creator>
                <pubDate>Tue, 18 Jun 2024 12:22:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/06/HTML---CSS-Only-Masonry-Layout.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A masonry layout is a grid-based design where items are arranged in a way that minimizes vertical gaps between them. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/masonry-layout.png" alt="Image" width="600" height="400" loading="lazy">
<em>an example of a masonry layout</em></p>
<p>Unlike traditional grids with fixed row heights, masonry layouts adjust the positioning of items dynamically based on their content height, creating a visually appealing and space-efficient arrangement.</p>
<h2 id="heading-key-characteristics-of-masonry-layouts">Key Characteristics of Masonry Layouts</h2>
<ul>
<li>Items can have varying heights, which makes the layout look more organic and less uniform when compared to standard grids. </li>
<li>Items are positioned to fill vertical gaps, creating a tightly packed layout without large spaces between items.</li>
<li>Masonry layouts can adapt to different screen sizes, adjusting the number of columns and the positioning of items accordingly.</li>
<li>The layout is often used for galleries, portfolios, and other visual content where an aesthetically pleasing presentation is important.</li>
</ul>
<h3 id="heading-common-uses">Common Uses</h3>
<ul>
<li>Image Galleries: Displaying images of different sizes without cropping.</li>
<li>Blog Layouts: Arranging posts of varying lengths.</li>
<li>E-commerce Sites: Showcasing products with different dimensions.</li>
</ul>
<h3 id="heading-how-it-works">How It Works</h3>
<p>Masonry layouts are often implemented using CSS Grid or JavaScript libraries like Masonry.js. Here, we'll focus on the CSS Grid approach.</p>
<h2 id="heading-how-to-create-a-masonry-layout">How to Create a Masonry Layout</h2>
<h3 id="heading-step-1-set-up-your-project">Step 1: Set Up Your Project</h3>
<ul>
<li>Create a project folder: Create a folder for your project on your computer.</li>
<li>Create HTML and CSS files: Inside the project folder, create two files: <code>index.html</code> and <code>styles.css</code>.</li>
</ul>
<pre><code class="lang-folder">Masonry/
├── index.html
└── styles.css
</code></pre>
<h3 id="heading-step-2-write-the-html">Step 2: Write the HTML</h3>
<ul>
<li>Use a text editor like Visual Studio Code, Sublime Text, or any other editor you prefer.</li>
<li>Add the basic structure of an HTML document by pressing <code>Shift+!</code></li>
<li>Change the title from Document to "CSS Masonry Layout"</li>
<li>Below the title, link your <code>styles.css</code> file as shown below:</li>
</ul>
<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">title</span>&gt;</span>CSS Masonry Layout<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    /** Link styles.css **/
        <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">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>
<ul>
<li>After setting up your HTML structure, create the different divisions for your layout within the body area.</li>
</ul>
<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">"masonry"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item1"</span>&gt;</span>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> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item2"</span>&gt;</span>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> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item3"</span>&gt;</span>Item 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">"item item4"</span>&gt;</span>Item 4<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">"item item5"</span>&gt;</span>Item 5<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">"item item6"</span>&gt;</span>Item 6<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">"item item7"</span>&gt;</span>Item 7<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">"item item8"</span>&gt;</span>Item 8<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">"item item9"</span>&gt;</span>Item 9<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">"item item10"</span>&gt;</span>Item 10<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>
<ul>
<li><code>&lt;div class="masonry"&gt;</code> is the container for our masonry layout. We'll use CSS Grid to create the masonry effect inside this container.</li>
<li><code>&lt;div class="item item1"&gt;Item 1&lt;/div&gt;</code> to <code>&lt;div class="item item10"&gt;Item 10&lt;/div&gt;</code> are the individual items (or boxes) inside our masonry layout. Each item has a class of <code>item</code> to style them uniformly and a specific class (for example: <code>item1</code>, <code>item2</code>, and so on) to apply unique styles—like different heights and colors—to each item.</li>
</ul>
<p>Breakdown of the CSS classes:</p>
<ul>
<li><code>item</code>: This class is used to style all items uniformly. It sets the background color, padding, box-sizing, box shadow, border-radius, and transitions for the items.</li>
<li><code>item1</code> to <code>item10</code>: These classes are used to set specific styles for each item. For example, <code>item1</code> might have a different height and background color than <code>item2</code>, and so on. These classes will be used in the CSS to apply specific styles.</li>
</ul>
<h4 id="heading-step-3-style-with-css">Step 3: Style with CSS</h4>
<ul>
<li>Open <code>styles.css</code> in a text editor: Use the same text editor to open your CSS file.</li>
<li>Add some basic styles for the <code>body</code> and the <code>masonry</code> container.</li>
</ul>
<pre><code class="lang-css"> <span class="hljs-selector-tag">body</span> {
        <span class="hljs-attribute">font-family</span>: Arial, sans-serif;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f0f0f0</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
    }
    <span class="hljs-selector-class">.masonry</span> {
        <span class="hljs-attribute">display</span>: grid;
        <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">200px</span>, <span class="hljs-number">1</span>fr));
        <span class="hljs-attribute">grid-auto-rows</span>: <span class="hljs-number">10px</span>;
        <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
    }
</code></pre>
<p>What this means:</p>
<ul>
<li><code>body</code> sets the font, background color, padding, and removes default margin.</li>
<li><code>.masonry</code> uses CSS Grid to create a responsive layout with columns that are at least <code>200px</code> wide and automatically fills the available space. The rows have a base height of <code>10px</code>, and there's a <code>20px</code> gap between items.</li>
</ul>
<p>Add styles for the items inside the masonry layout.</p>
<pre><code class="lang-css"> <span class="hljs-selector-class">.item</span> {
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffffff</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">box-sizing</span>: border-box;
        <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">6px</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.1</span>);
        <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
        <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">0.3s</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">font-size</span>: <span class="hljs-number">1.2em</span>;
        <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
    }
    <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:hover</span> {
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">10px</span>);
    }
</code></pre>
<p>What the above means:</p>
<ul>
<li><code>.item</code> sets a white background, padding, box shadow for elevation, rounded corners, and a hover effect to lift the item slightly. <code>display: flex</code> centers the content.</li>
<li><code>.item:hover</code> will add a transform effect when the item is hovered on.</li>
</ul>
<p>Set specific dimensions and colors by defining specific styles for each item to give them different heights and background colors.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.item1</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ff6f61</span>; }
<span class="hljs-selector-class">.item2</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6b5b95</span>; }
<span class="hljs-selector-class">.item3</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#88b04b</span>; }
<span class="hljs-selector-class">.item4</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#d65076</span>; }
<span class="hljs-selector-class">.item5</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffb347</span>; }
<span class="hljs-selector-class">.item6</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#45b8ac</span>; }
<span class="hljs-selector-class">.item7</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#e94b3c</span>; }
<span class="hljs-selector-class">.item8</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6c5b7b</span>; }
<span class="hljs-selector-class">.item9</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#00a86b</span>; }
<span class="hljs-selector-class">.item10</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#b565a7</span>;}
</code></pre>
<ul>
<li>Each item class (.item1, .item2, and so on) sets the number of rows it spans (grid-row: span X;) and assigns a unique background color.</li>
</ul>
<h3 id="heading-step-4-view-your-layout">Step 4: View Your Layout</h3>
<p>Open <code>index.html</code> in a web browser to see the masonry layout.</p>
<p>You can add more items, change colors, or adjust sizes to fit your design needs. Below is the layout we created.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/06/masonry-layout-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-putting-it-all-together">Putting it all together</h3>
<p>The <code>index.html</code> file should look like this:</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">title</span>&gt;</span>CSS Masonry Layout<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">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">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"masonry"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item1"</span>&gt;</span>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> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item2"</span>&gt;</span>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> <span class="hljs-attr">class</span>=<span class="hljs-string">"item item3"</span>&gt;</span>Item 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">"item item4"</span>&gt;</span>Item 4<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">"item item5"</span>&gt;</span>Item 5<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">"item item6"</span>&gt;</span>Item 6<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">"item item7"</span>&gt;</span>Item 7<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">"item item8"</span>&gt;</span>Item 8<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">"item item9"</span>&gt;</span>Item 9<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">"item item10"</span>&gt;</span>Item 10<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">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The <code>styles.css</code> file will look like this:.</p>
<pre><code class="lang-css">    <span class="hljs-selector-tag">body</span> {
        <span class="hljs-attribute">font-family</span>: Arial, sans-serif;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f0f0f0</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
    }
    <span class="hljs-selector-class">.masonry</span> {
        <span class="hljs-attribute">display</span>: grid;
        <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">200px</span>, <span class="hljs-number">1</span>fr));
        <span class="hljs-attribute">grid-auto-rows</span>: <span class="hljs-number">10px</span>;
        <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
    }

    <span class="hljs-selector-class">.item</span> {
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffffff</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
        <span class="hljs-attribute">box-sizing</span>: border-box;
        <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">6px</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.1</span>);
        <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">8px</span>;
        <span class="hljs-attribute">transition</span>: transform <span class="hljs-number">0.3s</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">font-size</span>: <span class="hljs-number">1.2em</span>;
        <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
    }

    <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:hover</span> {
        <span class="hljs-attribute">transform</span>: <span class="hljs-built_in">translateY</span>(-<span class="hljs-number">10px</span>);
    }

    <span class="hljs-comment">/* Specific dimensions and colors for each item */</span>
    <span class="hljs-selector-class">.item1</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ff6f61</span>; }
    <span class="hljs-selector-class">.item2</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6b5b95</span>; }
    <span class="hljs-selector-class">.item3</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#88b04b</span>; }
    <span class="hljs-selector-class">.item4</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#d65076</span>; }
    <span class="hljs-selector-class">.item5</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#ffb347</span>; }
    <span class="hljs-selector-class">.item6</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">15</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#45b8ac</span>; }
    <span class="hljs-selector-class">.item7</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">20</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#e94b3c</span>; }
    <span class="hljs-selector-class">.item8</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">10</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#6c5b7b</span>; }
    <span class="hljs-selector-class">.item9</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">25</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#00a86b</span>; }
    <span class="hljs-selector-class">.item10</span> { <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">30</span>; <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#b565a7</span>; }
</code></pre>
<h2 id="heading-summary">Summary</h2>
<p>A masonry layout is an effective way to display content with varying heights in a grid-like structure without large vertical gaps, making it ideal for image galleries, blogs, and portfolios. </p>
<p>Using CSS Grid, you can create a responsive and visually appealing masonry layout with minimal code.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Bento Grids Design in Your Web Projects ]]>
                </title>
                <description>
                    <![CDATA[ I believe we may have all noticed the trend of meticulously organized web layouts reminiscent of Japanese bento boxes. These 'Bento Grids' have swiftly gained traction, offering a visually appealing and structurally cohesive way to present content on... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/bento-grids-in-web-design/</link>
                <guid isPermaLink="false">66bb88f4add24ba4273250de</guid>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ projects ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Jaja ]]>
                </dc:creator>
                <pubDate>Thu, 04 Apr 2024 10:06:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/04/Article-cover.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I believe we may have all noticed the trend of meticulously organized web layouts reminiscent of Japanese bento boxes. These 'Bento Grids' have swiftly gained traction, offering a visually appealing and structurally cohesive way to present content online.</p>
<p>In this article, we'll delve into the origins, rise, and practical implementation of the bento grid trend, exploring how it intersects aesthetics with functionality in modern web design.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li>Fundamentals of HTML and CSS (CSS Grid)</li>
<li>Basics of Web Design</li>
</ul>
<h2 id="heading-the-philosophy-behind-bento-grids">The Philosophy Behind Bento Grids</h2>
<p>The concept of bento grids traces back to the Japanese tradition of serving a variety of dishes in a single, segmented container known as a bento box. This method of presentation not only ensures a balanced meal but also pleases the eye with its organization and simplicity.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Bento-Japenese.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Bento Japanese Box</em></p>
<p>Translated into web design, bento grids offer a similar experience: diverse content segmented into distinct areas, making it both accessible and aesthetically balanced.</p>
<p>The bento grid philosophy hinges on compartmentalization and organization. It creates a predictable rhythm that users can follow, reducing cognitive load and enhancing the overall user experience. The design's symmetry and order offers a sense of calm and control, appealing to users' desire for simplicity and structure amidst the chaos of the internet.</p>
<h2 id="heading-the-rise-of-bento-grids">The Rise of Bento Grids</h2>
<p>While the use of grids in design is not new, the specific trend of bento grids began to gain traction as designers sought to create more organized and mobile-responsive layouts. </p>
<p>Powerhouses like Apple use this design pattern in promotional videos for their products as well.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/Apple-mac-promotional-infographic.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Apple mac promotional infographic</em></p>
<p>The trend also saw a surge in popularity with the advent of CSS Grid Layout and the growing focus on minimalist design that doesn't sacrifice functionality for form.</p>
<p>Platforms that emphasize content, such as online magazines, educational sites, and portfolios, were among the early adopters of bento grids. Their adoption highlighted the grid's ability to present diverse content types in a harmonious layout, thereby improving navigation and readability.</p>
<h2 id="heading-examining-the-trend">Examining the Trend</h2>
<p>Clean lines, geometric shapes, and a clear space division often characterize modern bento grids. They usually consist of:</p>
<ul>
<li>The title of a feature</li>
<li>A short description of the feature</li>
<li>Some infographic or interactive content.</li>
</ul>
<p>This trend has been propelled by its positive impact on user experience. A well-implemented bento grid guides users through the website with ease, allowing quick access to information without overwhelming them with choices.</p>
<h2 id="heading-pros-of-using-bento-grids">Pros of Using Bento Grids</h2>
<ol>
<li><strong>Enhanced Organization and Cohesion</strong>: Bento grids bring a high level of organization to web design, allowing for a cohesive presentation of varied content. This segmentation makes it easier for users to digest information in a structured manner.</li>
<li><strong>Aesthetic Appeal</strong>: The symmetry and clean lines inherent in bento grids are visually appealing, providing a neat and professional look that can enhance the visual identity of a website.</li>
<li><strong>Reduced Scroll Fatigue</strong>: By efficiently utilizing space within a single viewport, bento grids can display a significant amount of content, which can reduce the need for excessive scrolling.</li>
<li><strong>Metaphorical Clarity</strong>: The bento box metaphor effectively communicates the concept of a complete and balanced experience, which can be particularly useful for showcasing product features or a portfolio of work.</li>
<li><strong>Improved Navigation</strong>: The predictability and order of bento grids aid in straightforward navigation, as users can easily move from one compartmentalized section to another.</li>
<li><strong>Compatibility with Responsive Design</strong>: Bento grids seamlessly integrate with responsive design principles, facilitating effortless adjustment of a website's layout to accommodate diverse screen sizes and devices.</li>
<li><strong>Focus on Content</strong>: The grid layout emphasizes content without unnecessary distractions, which can be crucial for sites where content is important, such as online galleries or information-driven platforms. </li>
<li><strong>Facilitates Comprehensive Product Capture</strong>: In the context of showcasing products, bento grids offer users the convenience of capturing all essential information at once. With content neatly organized within distinct compartments, users can easily screenshot or save a single view of the grid, ensuring they capture all relevant details without the need for multiple interactions or navigating through various pages.</li>
</ol>
<h2 id="heading-cons-of-bento-grids">Cons of Bento Grids</h2>
<ol>
<li><strong>Potential Information Overload</strong>: While bento grids can reduce cognitive load through organization, there's a risk of cramming too much information into a single screen, potentially overwhelming users.</li>
<li><strong>Limited Visual Hierarchy</strong>: The uniform structure of bento grids can sometimes lead to a lack of visual hierarchy, making it harder for users to determine the importance of certain content over others.</li>
<li><strong>Considerations Regarding Hick's Law</strong>: A densely packed grid presents users with a multitude of options, potentially prolonging their decision-making process. This abundance of choices can result in the paradox of choice, where <a target="_blank" href="https://lawsofux.com/hicks-law/">users experience indecision or slower navigation due to the overwhelming array of options available</a>.</li>
<li><strong>Design Rigidity</strong>: The structured nature of bento grids can sometimes restrict creative design elements and lead to a monotonous user experience if not implemented with variation and dynamic content.</li>
<li><strong>SEO Challenges</strong>: Search engines may have difficulty parsing the relevance of content when it's distributed across numerous grid compartments, potentially impacting SEO if not structured properly.</li>
<li><strong>Accessibility Concerns</strong>: The compartmentalized nature of bento grids might present accessibility challenges, particularly for users who rely on screen readers or keyboard navigation, if not designed with accessibility standards in mind.</li>
</ol>
<h2 id="heading-bento-grids-in-practice">Bento Grids in Practice</h2>
<p>Creating bento grids typically involves CSS grid layout and flexbox, which offer robust solutions for creating complex layouts with ease. Bento grids are favored for their flexibility and responsiveness, allowing content to reflow seamlessly across different screen sizes.</p>
<p>For this article, here’s the design we’re going to create the interface below:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/desktop-design-to-recreate.png" alt="Image" width="600" height="400" loading="lazy">
<em>desktop design to recreate</em></p>
<p>To begin, create a couple of <code>divs</code> in your markup.</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">"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">"item"</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">"item"</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">"item"</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">"item"</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">"item"</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">body</span>&gt;</span>
</code></pre>
<p>Then utilize the <code>grid</code> property, <code>grid-template-columns</code>, and <code>grid-template-rows</code> to define the number of rows and columns you desire.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid</span> {
  <span class="hljs-attribute">background</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">36</span>, <span class="hljs-number">100%</span>, <span class="hljs-number">99%</span>);
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">1500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">1000px</span>;
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">1.5vw</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">1vw</span>;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">6</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-rows</span>: auto;
}
</code></pre>
<p>The final ingredient to achieving a bento-style grid lies in the use of the <code>grid-template-areas</code> property which is used to name grid areas according to the position you want them to occupy on the page.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid</span> {
  <span class="hljs-attribute">background</span>: <span class="hljs-built_in">hsl</span>(<span class="hljs-number">36</span>, <span class="hljs-number">100%</span>, <span class="hljs-number">99%</span>);
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">max-width</span>: <span class="hljs-number">1500px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">1000px</span>;
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">1.5vw</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">1vw</span>;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">6</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-rows</span>: auto;
  <span class="hljs-attribute">grid-template-areas</span>:
    <span class="hljs-string">"hero hero hero hero aside2 aside2"</span>
    <span class="hljs-string">"hero hero hero hero aside2 aside2"</span>
    <span class="hljs-string">"hero hero hero hero aside2 aside2"</span>
    <span class="hljs-string">"hero hero hero hero aside2 aside2"</span>
    <span class="hljs-string">"aside3 aside3 aside4 aside4 aside5 aside5 "</span>;
}
</code></pre>
<p>Finally, assign those names to the exact element you want to take up that space.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.item</span> {
  <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid <span class="hljs-number">#464545</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
}

<span class="hljs-selector-class">.grid</span> <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:nth-child(1)</span> {
  <span class="hljs-attribute">grid-area</span>: hero;
}
<span class="hljs-selector-class">.grid</span> <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:nth-child(2)</span> {
  <span class="hljs-attribute">grid-area</span>: aside2;
}

<span class="hljs-selector-class">.grid</span> <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:nth-child(3)</span> {
  <span class="hljs-attribute">grid-area</span>: aside3;
}
<span class="hljs-selector-class">.grid</span> <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:nth-child(4)</span> {
  <span class="hljs-attribute">grid-area</span>: aside4;
}

<span class="hljs-selector-class">.grid</span> <span class="hljs-selector-class">.item</span><span class="hljs-selector-pseudo">:nth-child(5)</span> {
  <span class="hljs-attribute">grid-area</span>: aside5;
}
</code></pre>
<p>You should have this result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/01-Bento-structure-achieved-.png" alt="Image" width="600" height="400" loading="lazy">
<em>Bento structure achieved</em></p>
<p>All that’s left is to fill the boxes with their appropriate content and assets. You can some assets/content in this <a target="_blank" href="https://github.com/Daiveedjay/Bento/tree/main/images">repo</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/02-Bento-with-content-filled.png" alt="Image" width="600" height="400" loading="lazy">
<em>Bento Grid with its content filled</em></p>
<p>Another usefulness of the <code>grid-template-areas</code> property is the ease by which you can achieve responsiveness with it. In our example, to make the page responsive, you pass in a new string pair on your preferred threshold.</p>
<p>On tablet screens:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">1000px</span>) {
  <span class="hljs-selector-class">.grid</span> {
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">1</span>fr);
    <span class="hljs-attribute">grid-template-areas</span>:
      <span class="hljs-string">"hero   hero   hero   hero"</span>
      <span class="hljs-string">"hero   hero   hero   hero"</span>
      <span class="hljs-string">"aside2 aside2 aside2 aside3"</span>
      <span class="hljs-string">"aside4 aside4 aside5 aside5"</span>;
  }
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/03-Tablet-screens.png" alt="Image" width="600" height="400" loading="lazy">
<em>Tablet Screens</em></p>
<p>And on smaller screens:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> screen <span class="hljs-keyword">and</span> (<span class="hljs-attribute">max-width:</span> <span class="hljs-number">750px</span>) {
  <span class="hljs-selector-class">.grid</span> {
    <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">grid-template-areas</span>:
      <span class="hljs-string">"hero   hero   hero"</span>
      <span class="hljs-string">"hero   hero   hero"</span>
      <span class="hljs-string">"aside2 aside2 aside2"</span>
      <span class="hljs-string">"aside3 aside3 aside3"</span>
      <span class="hljs-string">"aside4 aside4 aside4"</span>
      <span class="hljs-string">"aside5 aside5 aside5"</span>;
  }
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/04/04-Smaller-screens.png" alt="Image" width="600" height="400" loading="lazy">
<em>Smaller screens</em></p>
<h2 id="heading-common-rules-of-bento-grids">Common Rules of Bento Grids</h2>
<p>Here are some good rules of thumb when building bento grids:</p>
<ul>
<li><strong>Group Related Content</strong>: One of the fundamental principles of bento grids is to group related content together within each segment. This enhances the user's ability to quickly locate and understand the information they're seeking. By organizing content logically, designers can improve user engagement and satisfaction.</li>
<li><strong>Vary Box Sizes</strong>: Avoid using the same size for every box within the grid. Varying box sizes can create visual interest and hierarchy, drawing attention to key elements while maintaining overall balance. This variation can help guide users through the content and highlight important information effectively.</li>
<li><strong>Establish Visual Hiererchy</strong>: Although varying box sizes contribute to visual hierarchy, establishing visual hierarchy encompasses a broader range of design elements. In addition to box sizes, designers should consider factors such as colour, typography, and placement to prioritize certain elements over others.</li>
<li><strong>Prioritize Center Square</strong>: In traditional bento grids, the center square often holds a special significance and acts as a focal point. Designers can use this central square to showcase critical information or highlight key features, effectively punctuating the grid and drawing users' attention to its core elements.</li>
<li><strong>Limit the Number of Boxes</strong>: To maintain clarity and avoid overwhelming users, it's recommended to use nine or fewer boxes within the bento grid. Limiting the number of boxes ensures that the layout remains manageable and facilitates easier navigation and comprehension for users.</li>
<li><strong>Consider Swirl Pattern</strong>: While not a strict rule, considering a swirl pattern can add an extra layer of visual interest to the bento grid design. This involves arranging content in a curved or swirling pattern within the grid, creating a dynamic and engaging layout that encourages exploration.</li>
</ul>
<h2 id="heading-additional-information">Additional Information</h2>
<p>I’d like to point out a couple of things in the article not highlighted.</p>
<ul>
<li>First and foremost, the article was inspired by <a target="_blank" href="https://x.com/itsdesignertom/status/1764856109754667243?s=20">Tom Geoco</a>’s video on bento grids.</li>
<li><a target="_blank" href="https://bentogrids.com/">BentoGrids</a> is an excellent resource for finding design inspiration if you’re interested. If you’re interested in the full code, here’s the repo, <a target="_blank" href="https://github.com/Daiveedjay/Bento">GitHub</a>, and the Live version. <a target="_blank" href="https://bentogrid.netlify.app/">Demo</a>.</li>
<li>The design inspiration for the grid we built was gotten from <a target="_blank" href="https://www.frontendmentor.io/challenges/news-homepage-H6SWTa1MFl">FrontEnd Mentor</a>.</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Bento grids stand out as a significant trend in the modern web design landscape, offering a blend of aesthetic appeal and functional clarity. They represent a design ethos that values order, beauty, and user-centricity. </p>
<p>As web technologies evolve, the principles underlying bento grids will continue to inform best practices, encouraging designers to create experiences that are not only visually compelling but also intuitively navigable.</p>
<h3 id="heading-contact-information">Contact Information</h3>
<p>Want to connect or contact me? Feel free to hit me up on the following:</p>
<ul>
<li>Twitter / X: <a target="_blank" href="https://twitter.com/JajaDavid8">@jajadavid8</a></li>
<li>LinkedIn: <a target="_blank" href="https://www.linkedin.com/in/david-jaja-8084251b4/">David Jaja</a></li>
<li>Email: Jajadavidjid@gmail.com</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Flexbox vs Grid in CSS – Which Should You Use? ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever had issues with replicating a particular user interface from a Figma design? Do you find it difficult displaying elements in different sections of your browser screen? A major cause of rift between user interface (UI) designers and fron... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/flexbox-vs-grid-in-css/</link>
                <guid isPermaLink="false">66c71fd6cdd5b7ce3d9c37e8</guid>
                
                    <category>
                        <![CDATA[ css flex ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ layout ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Mabel Obadoni ]]>
                </dc:creator>
                <pubDate>Fri, 16 Feb 2024 11:02:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/02/pankaj-patel-6JVlSdgMacE-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever had issues with replicating a particular user interface from a Figma design? Do you find it difficult displaying elements in different sections of your browser screen?</p>
<p>A major cause of rift between user interface (UI) designers and frontend developers is the issue of having an awesome UI design being difficult to translate into real life features.</p>
<p>Almost every frontend developer has faced similar fears at certain points during their coding journey. This article will help you understand how CSS displays work with regards to flexbox and grid layout.</p>
<h2 id="heading-table-of-contents">Table of Contents:</h2>
<ul>
<li><a class="post-section-overview" href="#heading-origin-of-css">Origin of CSS</a></li>
<li><a class="post-section-overview" href="#heading-basic-structure-of-css">Basic Structure of CSS</a></li>
<li><a class="post-section-overview" href="#heading-css-layout-flex-and-grid">CSS Layout (Flex and Grid)</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-flex-layout-in-css">How to Use the Flex Layout in CSS</a></li>
<li><a class="post-section-overview" href="#heading-how-to-use-the-flex-layout-in-css">How to Use the Grid Layout in CSS</a></li>
<li><a class="post-section-overview" href="#heading-similarities-between-flex-and-grid">Similarities between Flex and Grid</a></li>
<li><a class="post-section-overview" href="#heading-when-to-use-flex">When to Use Flex</a></li>
<li><a class="post-section-overview" href="#heading-when-to-use-grid">When to Use Grid</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-origin-of-css">Origin of CSS</h2>
<p>The earliest websites were not only static, but were also text-based. During the early years of the World Wide Web, web pages were written in markup languages such as XHTML and the like.</p>
<p>This is what they looked like:</p>
<p><img src="https://lh5.googleusercontent.com/Wx0Au7mNXzu7gi_nFVSJ1T-CRXYiBBcaXBMEEWYJ_GNvm7e3vsN1UTdkPXmGGuKicXmdl60JjMEm2mJQT4vUmJc4oAxTfMiwV-MoK8tMIwhNcQZo58ziVlONzkRc9CrkAMYfz2GaxQykIOacs9-vAv4" alt="Image" width="686" height="385" loading="lazy">
<em><a target="_blank" href="https://www.history.com/news/the-worlds-first-web-site">https://www.history.com/news/the-worlds-first-web-site</a></em></p>
<p>With advancements in various technologies, technology enthusiasts were interested in making websites look more pleasant by adding some design. This led to the development of Cascading Style Sheets, better known as CSS. </p>
<p>Although CSS has gone through several evolutions, it is responsible for the aesthetics of websites. Imagine a website or a software application with just text and no design.</p>
<p>Hey! This article is not about history, so let’s get straight to business.</p>
<p>As a software developer majoring in client side applications (often referred to as front-end development), you’d agree with me that CSS is that lovely fellow who looks simple yet sophisticated. </p>
<p>CSS can keep you awake at night while trying to find out why your page is not aligning as expected or the reason your page content is chopped off on certain screens and not responsive too.</p>
<p>One of the reasons why beginners in software development often abandon front-end to major in back-end is the “stress” that comes with writing CSS code, especially with vanilla CSS where you have to manually input virtually every style rule. This is because CSS requires some level of calculation mixed with attention to the most minimal detail.</p>
<p>A major aspect of CSS that often creates confusion is the CSS layout — writing the CSS rule for the page layout can be a bit confusing as a beginner.</p>
<p>In the sections that follow, we'll focus on:</p>
<ul>
<li>The similarities between flex and grid displays.</li>
<li>When to use flex or grid.</li>
</ul>
<h2 id="heading-basic-structure-of-css"><strong>Basic Structure of CSS</strong></h2>
<p>Before discussing the CSS display in detail, let’s take a brief look at the CSS structure. </p>
<p>For starters, the CSS structure is a box-model. This means that every webpage is treated like a box, similar to having a pizza in a pizza box. </p>
<p>The pizza box here represents the browser page while the pizza represents the content of your website or application, which can be text, graphics, or multimedia.</p>
<p><img src="https://lh7-us.googleusercontent.com/EJbG9BG5EZ7CU9sBtOQJVBWo7cbc8nwG8pjYxqQ6kgll7lTN7wH8XQYy35zZFgbMhiQhZLy3BqnEA-brNtaS8NBcB-XPLMzk0zBvAr-frniqSogpYmDWs7qqgiloBjXuNK2mWZIIymLfpfa880m1HjU" alt="Image" width="1600" height="1067" loading="lazy">
<em>A box of pizza</em></p>
<p><img src="https://lh7-us.googleusercontent.com/lxBLqGMf-ZhMcZwKDpCPRHmax_Y3ZBst69uUF0pmZBZdmuRnh_woEy48OzbqXBwGAy5I38HAZ5SFW5fU-3LwsJArJNX3KBk0E2K6d2nH7SoXZKGHwJpQlLtxZrlbxwIWnjO9kLSfyi-wHf7u1WWAy4A" alt="Image" width="1600" height="900" loading="lazy">
<em>CSS box model</em></p>
<h2 id="heading-css-layout-flex-and-grid"><strong>CSS Layout (Flex and Grid)</strong></h2>
<p>Now that you know how CSS structures the content of every web or application page, a vital aspect of CSS which you should get a grasp of is the layout, which is the crux of this article.</p>
<p>In architecture, every building has its structure. The structure for a commercial building might differ from that of a residential building. Same goes for front-end development. </p>
<p>The purpose of the application goes a long way in the selecting a layout for the. For instance, an e-commerce website would opt for a grid layout for proper arrangement and display of their products.</p>
<p>The layout of every website or application determines how the content on the page will be arranged: either in stacks of rows and columns or just columns across various screen-sizes. </p>
<p>It is also worthy to note that you can use more than one display on a particular webpage. This means that you can display a particular <code>div</code> as a grid and another <code>div</code> as a flexbox. It all boils down to the content of each <code>div</code> and how you want them to appear.</p>
<p>There are two ways to design the layout of a web page’s content in CSS:</p>
<ul>
<li>Flex</li>
<li>Grid</li>
</ul>
<h3 id="heading-how-to-use-the-flex-layout-in-css">How to Use the Flex Layout in CSS</h3>
<p>The flex layout uses a method of arranging the web content in rows (main axis) or columns (perpendicular axis). This implies that it is a one-dimensional layout. The main axis can move in reverse order, from right to left.</p>
<p>The flex direction can be set to:</p>
<ul>
<li>Row</li>
<li>Row-reverse</li>
<li>Column</li>
<li>Column-reverse</li>
</ul>
<p>Using flexbox does not split the screen or content into equal parts. It is worthy to note that, flexbox doesn’t consider splitting content into equal columns across the row or stacking columns in the same alignment. Rather, it expands or shrinks the content to contain the available screen space.</p>
<p>Below is a diagram of a flex display using rows:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/Flex-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>A graphical representation of a display set to flex</em></p>
<h4 id="heading-how-to-set-display-to-flex">How to Set Display to Flex</h4>
<p>To create a flex layout:</p>
<ul>
<li>Give the parent element a style rule of flex display</li>
<li>Give the children element some margin and padding for a better look</li>
<li>Specify the direction of the flex if there is a need to</li>
</ul>
<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">title</span>&gt;</span> Setting Display to Flex<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
    <span class="hljs-selector-class">.fl</span>{
        <span class="hljs-attribute">display</span>: flex;
        <span class="hljs-attribute">flex-wrap</span>: wrap;
    }
    <span class="hljs-selector-class">.ex</span> {
        <span class="hljs-attribute">flex-direction</span>:row;
        <span class="hljs-attribute">flex</span>: <span class="hljs-number">1</span> <span class="hljs-number">0</span> <span class="hljs-number">100px</span>; 
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">5px</span>; 
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>; 
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0000FF</span>; 
        <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#ffff</span>; <span class="hljs-comment">/* I added a border all round each column for better visibility and separation of the columns */</span>
    }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</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">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fl"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"ex"</span>&gt;</span>Content 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">"ex"</span>&gt;</span>Content 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">"ex"</span>&gt;</span>Content 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">"ex"</span>&gt;</span>Content 4<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">"ex"</span>&gt;</span>Content 5<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">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<p>The code above  styles the body by selecting the parent container and assigning it a layout of <code>flex</code>. Then the direction of the children element is set to <code>row</code> using the <code>flex-direction</code> rule.</p>
<h3 id="heading-how-to-use-the-grid-layout-in-css">How to Use the Grid Layout in CSS</h3>
<p>The grid layout, on the other hand, divides a web-page into 12 equal columns. These columns can be further split into the desired rows and columns. </p>
<p>The entire screen (100%) divided into 12 gives about 3.33% per column. The screen can also be styled using the number of columns in multiples of 2. That is: 2,4,6,8,10 and 12 with each number specifying the number of columns or width the element is expected to occupy.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/02/image-120.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h4 id="heading-how-to-set-display-to-grid">How to Set Display to Grid</h4>
<ul>
<li>Set the parent element's display to grid</li>
<li>Specify the dimension(i.e rows or columns) of the grid using the grid-template property</li>
<li>Give some spacing(margin,padding, row-gap, etc) to the child element so the grid can be more visible</li>
</ul>
<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">title</span>&gt;</span>Setting Display to Grid<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
    <span class="hljs-selector-class">.fl</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-comment">/* This would display the children elements in  three equal columns with equal width */</span>
        <span class="hljs-attribute">gap</span>: <span class="hljs-number">5px</span>; <span class="hljs-comment">/* To set a gap between  thegrid items */</span>
    }
    <span class="hljs-selector-class">.gr</span> {
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>; 
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#0000FF</span>; 
        <span class="hljs-attribute">border</span>: <span class="hljs-number">1px</span> solid <span class="hljs-number">#ffff</span>; <span class="hljs-comment">/* I added a border all round each column for better visibility and separation of the columns */</span>
    }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</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">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"gr"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"gr"</span>&gt;</span>Content 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">"gr"</span>&gt;</span>Content 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">"gr"</span>&gt;</span>Content 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">"gr"</span>&gt;</span>Content 4<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">"gr"</span>&gt;</span>Content 5<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">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h2 id="heading-similarities-between-flex-and-grid">Similarities between Flex and Grid</h2>
<ul>
<li><p><strong>They are both responsive layouts</strong>: Irrespective of which layout you decide to use for your application, provided that you style the properties correctly, both layout types are responsive to different screen sizes.</p>
</li>
<li><p><strong>Setting the parent element's layout first</strong>: In styling a flex or grid layout, the parent element is the one styled with the exact layout in question.</p>
</li>
</ul>
<h2 id="heading-when-to-use-flex"><strong>When to Use Flex</strong></h2>
<p>CSS flex is popular for its order ability (row-reverse, column-reverse), which enables the developer to reorder content without having to change the HTML content manually. There are several uses cases of the CSS flex, such as:</p>
<ul>
<li><strong>Building One-dimensional Layouts:</strong> For web-pages or sections with a single layout, it is best to use flex as it helps in proper arrangement of the content. </li>
<li><strong>Alignment and Distribution of Content</strong>: Thanks to justify-content, <code>align-self</code> and other properties, alignment and distribution of content is made easy using flex.</li>
<li><strong>Displaying Columns in Equal heights</strong>: Using the <code>align-items</code> property and setting it to a value of <code>stretch</code>, that is: <code>align-items:stretch</code>, CSS flex ensures that columns within a flexbox are of equal heights. 
This implies that if there is a higher column, other columns will be stretched to meet up with the highest column. You can use CSS flex to display your columns in equal height irrespective of the height of the content.</li>
</ul>
<h2 id="heading-when-to-use-grid"><strong>When to Use Grid</strong></h2>
<p>The grid layout is the most commonly used by frontend developers because it allows you to place elements on different sections of the browser page while maintaining proper alignment.  You can use the grid layout when:</p>
<ul>
<li><strong>Building a Responsive Design:</strong> Often times, user interfaces are developed to be adaptable to whatever screen they're being displayed on. In such cases, the grid layout is your best bet because it gives room to flexibility and resizing of the element.</li>
<li><strong>Control of whitespace:</strong> Unlike the flex display that leaves some white space at the extreme, the CSS grid controls white space by distributing elements equally along the row and also based on the allocated column space.</li>
<li><strong>Consistency in Design Layout:</strong> The CSS grid offers a consistent pattern in the structure of a web page. This arrangement of elements makes future editing of the page easier.</li>
</ul>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>One tip that comes very handy when styling a page is to choose which of the display modes to employ. </p>
<p>Once that is settled, the various sections of the page can follow suit bearing in mind what the entire body holds. </p>
<p>Although not an advice, recent practices have seen developers use grid more often than flexbox. Whichever the case, ensure not to mix up the code for the respective displays so you do not run into errors.</p>
<p>Happy Coding!  </p>
 ]]>
                </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[ CSS Grid Handbook – Complete Guide to Grid Containers and Grid Items ]]>
                </title>
                <description>
                    <![CDATA[ CSS Grid gives you the tools to create basic and advanced website layouts in responsive ways that look great on mobile, tablet, and desktop devices. This tutorial discusses everything you need to know to use CSS Grid like a pro. Table of Contents Wh... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/complete-guide-to-css-grid/</link>
                <guid isPermaLink="false">66ba0ddfc003a1736007f49a</guid>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ responsive design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Oluwatobi Sofela ]]>
                </dc:creator>
                <pubDate>Thu, 16 Mar 2023 18:19:27 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738338779416/5e58d695-6840-40da-84bc-c2b2428c16db.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>CSS Grid gives you the tools to create basic and advanced website layouts in responsive ways that look great on mobile, tablet, and desktop devices.</p>
<p>This tutorial discusses everything you need to know to use CSS Grid like a pro.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grid">What Is CSS Grid?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-grid-container-vs-grid-item-whats-the-difference">Grid Container vs. Grid Item: What's the Difference?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-a-grid-value-in-css">What Is a <code>grid</code> Value in CSS?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-an-inline-grid-value-in-css">What Is an <code>inline-grid</code> Value in CSS?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-properties-for-specifying-a-grids-layout">Properties for Specifying a Grid's Layout</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-grid-containers-properties">What Are the Grid Container's Properties?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-template-columns-property">What Is CSS Grid's <code>grid-template-columns</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-template-rows-property">What Is CSS Grid's <code>grid-template-rows</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-justify-content-property">What Is CSS Grid's <code>justify-content</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-justify-items-property">What Is CSS Grid's <code>justify-items</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-align-content-property">What Is CSS Grid's <code>align-content</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-align-items-property">What Is CSS Grid's <code>align-items</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-grid-items-properties">What Are the Grid Item's Properties?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-justify-self-property">What Is CSS Grid's <code>justify-self</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-align-self-property">What Is CSS Grid's <code>align-self</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-column-start-property">What Is CSS Grid's <code>grid-column-start</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-column-end-property">What Is CSS Grid's <code>grid-column-end</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-column-property">What Is CSS Grid's <code>grid-column</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-row-start-property">What Is CSS Grid's <code>grid-row-start</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-row-end-property">What Is CSS Grid's <code>grid-row-end</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-row-property">What Is CSS Grid's <code>grid-row</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-area-property">What Is CSS Grid's <code>grid-area</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-css-grids-grid-template-areas-property">What Is CSS Grid's <code>grid-template-areas</code> Property?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-the-css-minmax-function-to-define-minimum-and-maximum-grid-sizes">How to Use the CSS <code>minmax()</code> function to Define Minimum and Maximum Grid Sizes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-use-the-css-repeat-function-to-define-grid-tracks-with-repeated-patterns">How to Use the CSS <code>repeat()</code> Function to Define Grid Tracks with Repeated Patterns</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-overview">Overview</a></p>
</li>
</ol>
<p>So, without any further ado, let's understand what CSS Grid is.</p>
<h2 id="heading-what-is-css-grid">What is CSS Grid?</h2>
<p>The CSS Grid Layout Module makes browsers display the selected HTML elements as grid <a target="_blank" href="https://codesweetly.com/css-box-model">box models</a>.</p>
<p>Grid allows you to easily resize and reposition a grid container and its items two-dimensionally.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>"Two-dimensionally" means grid modules allow simultaneous laying out of box models in rows and columns.</p>
</li>
<li><p>Use <a target="_blank" href="https://codesweetly.com/css-flexbox-explained">Flexbox</a> if you only need to resize and reposition elements one-dimensionally.</p>
</li>
</ul>
<h2 id="heading-grid-container-vs-grid-item-whats-the-difference">Grid Container vs. Grid Item: What's the Difference?</h2>
<p>A <strong>grid 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>grid</code> or <code>inline-grid</code>.</p>
<p>A <strong>grid item</strong> is any of the direct children of a grid container.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-container-grid-item-illustration-codesweetly.png" alt="Illustration of a grid container and a grid item" width="600" height="400" loading="lazy"></p>
<p><em>A grid container (the large yellow area in the image) is an HTML element whose display property's value is grid or inline-grid. Grid items (the smaller boxes within the yellow container) are the direct children of a grid container.</em></p>
<h2 id="heading-what-is-a-grid-value-in-css">What Is a <code>grid</code> Value in CSS?</h2>
<p><code>grid</code> tells browsers to display the selected HTML element as a block-level grid box model.</p>
<p>In other words, setting an element's <code>display</code> property's value to <code>grid</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> grid layout module.</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>: grid;
  <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-5ggr6k?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid</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 grid box models.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>The <code>display: grid</code> directive creates only a single-column grid container. Therefore, the grid items will display in the normal layout flow (one item below another).</p>
</li>
<li><p>Converting a node to a grid box model makes the element's direct children become grid items.</p>
</li>
<li><p>The <code>display: grid</code> directive only affects a box model and its direct children. It does not affect grandchildren nodes.</p>
</li>
</ul>
<p>Let's now discuss the <code>inline-grid</code> value.</p>
<h2 id="heading-what-is-an-inline-grid-value-in-css">What Is an <code>inline-grid</code> Value in CSS?</h2>
<p><code>inline-grid</code> tells browsers to display the selected HTML element as an inline-level grid box model.</p>
<p>In other words, setting an element's <code>display</code> property's value to <code>inline-grid</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> grid layout module.</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-grid;
  <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-ekpbac?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>inline-grid</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 grid box models.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>Converting a node to a grid box model makes the element's direct children become grid items.</p>
</li>
<li><p>The <code>display: inline-grid</code> directive only affects a box model and its direct children. It does not affect grandchildren nodes.</p>
</li>
</ul>
<h2 id="heading-properties-for-specifying-a-grids-layout">Properties for Specifying a Grid's Layout</h2>
<p>On converting a regular HTML element to a grid (or inline-grid) box model, the grid layout module provides two categories of properties for positioning the grid box and its direct children:</p>
<ul>
<li><p>Grid container's properties</p>
</li>
<li><p>Grid item's properties</p>
</li>
</ul>
<h2 id="heading-what-are-the-grid-containers-properties">What Are the Grid Container's Properties?</h2>
<p>A grid container's properties specify how browsers should layout items within the grid box model.</p>
<p><strong>Note:</strong> We define a grid container's property on the container, not its items.</p>
<p>The eight (8) types of grid container properties are:</p>
<ul>
<li><p><code>grid-template-columns</code></p>
</li>
<li><p><code>grid-template-rows</code></p>
</li>
<li><p><code>grid-auto-columns</code></p>
</li>
<li><p><code>grid-auto-rows</code></p>
</li>
<li><p><code>justify-content</code></p>
</li>
<li><p><code>justify-items</code></p>
</li>
<li><p><code>align-content</code></p>
</li>
<li><p><code>align-items</code></p>
</li>
</ul>
<p>Let's discuss the eight types now.</p>
<h2 id="heading-what-is-css-grids-grid-template-columns-property">What Is CSS Grid's <code>grid-template-columns</code> Property?</h2>
<p><strong>grid-template-columns</strong> specifies the number and widths of columns browsers should display in the selected grid container.</p>
<h3 id="heading-example-1-how-to-create-a-two-column-grid-container">Example 1: How to create a two-column grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">95px</span> <span class="hljs-number">1</span>fr;
  <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-uwtgsf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-columns</code> property to display two columns of different widths in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong> We used the <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> (fraction) unit</a> to scale the second column relative to the fraction of available space in the grid container.</p>
<h3 id="heading-example-2-how-to-create-a-three-column-grid-container">Example 2: How to create a three-column grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">15%</span> <span class="hljs-number">60%</span> <span class="hljs-number">25%</span>;
  <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-xaop69?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-columns</code> property to display three columns of different widths in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>You can use the <code>grid-auto-columns</code> property to specify default column widths for all the grid container's columns. For instance, <code>grid-auto-columns: 150px</code> will set default widths of <code>150px</code> for all columns. But a <code>grid-template-columns</code> declaration will override it.</p>
</li>
<li><p>Explicit grid columns are the columns you explicitly define with the <code>grid-template-columns</code> property.</p>
</li>
<li><p>Implicit grid columns are the columns browsers create automatically. We use the <code>grid-auto-columns</code> properties to specify <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">track</a> sizes for implicit columns.</p>
</li>
</ul>
<p><strong>Tip:</strong></p>
<ul>
<li><p>Use the CSS <code>repeat()</code> function to specify <code>grid-template-columns</code> values with repeated patterns. We will discuss the <code>repeat()</code> function later in this tutorial.</p>
</li>
<li><p>Use the <a target="_blank" href="https://codesweetly.com/css-column-gap-property">CSS <code>column-gap</code> property</a> to create gaps between grid columns.</p>
</li>
</ul>
<h2 id="heading-what-is-css-grids-grid-template-rows-property">What Is CSS Grid's <code>grid-template-rows</code> Property?</h2>
<p><strong>grid-template-rows</strong> specifies the number and heights of rows browsers should display in the selected grid container.</p>
<h3 id="heading-example-1-how-to-create-a-three-row-grid-container">Example 1: How to create a three-row grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">95px</span> <span class="hljs-number">1</span>fr <span class="hljs-number">70px</span>;
  <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-tbisxm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-rows</code> property to display three rows of different heights in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong> We used the <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> (fraction) unit</a> to scale the second row relative to the fraction of available space in the grid container.</p>
<h3 id="heading-example-2-how-to-create-a-three-row-and-four-column-grid-container">Example 2: How to create a three-row and four-column grid container</h3>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">90px</span> <span class="hljs-number">300px</span> <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">grid-template-columns</span>: auto auto auto auto;
  <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-e5vtot?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-rows</code> property to display three columns of different heights in the selected <code>&lt;section&gt;</code> grid container.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>You can use the <code>grid-auto-rows</code> property to specify default row heights for all the grid container's rows. For instance, <code>grid-auto-rows: 100px</code> will set default heights of <code>100px</code> for all rows. But a <code>grid-template-rows</code> declaration will override it.</p>
</li>
<li><p>Explicit grid rows are the rows you explicitly define with the <code>grid-template-rows</code> property.</p>
</li>
<li><p>Implicit grid rows are the rows browsers create automatically. We use the <code>grid-auto-rows</code> properties to specify <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">track</a> sizes for implicit rows.</p>
</li>
</ul>
<p><strong>Tip:</strong></p>
<ul>
<li><p>Use the CSS <code>repeat()</code> function to specify <code>grid-template-rows</code> values with repeated patterns. We will discuss the <code>repeat()</code> function later in this tutorial.</p>
</li>
<li><p>Use the <a target="_blank" href="https://codesweetly.com/css-row-gap-property">CSS <code>row-gap</code> property</a> to create gaps between grid rows.</p>
</li>
</ul>
<h2 id="heading-what-is-css-grids-justify-content-property">What Is CSS Grid's <code>justify-content</code> Property?</h2>
<p><strong>justify-content</strong> specifies how browsers should position a grid container's columns along its row axis.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>A row axis is sometimes called an inline axis.</p>
</li>
<li><p>The <code>justify-content</code> property works if the total column widths are less than the grid container's width. In other words, you need free space along the container's row axis to justify its columns left or right.</p>
</li>
</ul>
<p>The <code>justify-content</code> property accepts the following values:</p>
<ul>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
<li><p><code>stretch</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>
<p>Let's discuss these values.</p>
<h3 id="heading-what-is-justify-content-start-in-css-grid">What is <code>justify-content: start</code> in CSS Grid?</h3>
<p><code>start</code> positions the grid container's columns with its row-start edge.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-start-illustration-codesweetly.png" alt="Illustration of justify-content's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's start value positions columns to the grid container's row-start edge</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>: grid;
  <span class="hljs-attribute">justify-content</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <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-rkwg9r?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to position the <code>&lt;section&gt;</code>'s columns to the grid container's row-start edge.</p>
<h3 id="heading-what-is-justify-content-center-in-css-grid">What is <code>justify-content: center</code> in CSS Grid?</h3>
<p><code>center</code> positions the grid container's columns to the center of the grid's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-center-illustration-codesweetly.png" alt="Illustration of justify-content's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's center value positions columns to the center of the grid container</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>: grid;
  <span class="hljs-attribute">justify-content</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <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-ft8n3n?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to position the <code>&lt;section&gt;</code>'s columns to the center of the grid container.</p>
<h3 id="heading-what-is-justify-content-end-in-css-grid">What is <code>justify-content: end</code> in CSS Grid?</h3>
<p><code>end</code> positions a grid container's columns with its row-end edge.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-end-illustration-codesweetly.png" alt="Illustration of justify-content's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's end value positions columns to the grid container's row-end edge</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>: grid;
  <span class="hljs-attribute">justify-content</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <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-zzaxjf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to position the <code>&lt;section&gt;</code>'s columns to the grid container's row-end edge.</p>
<h3 id="heading-what-is-justify-content-space-between-in-css-grid">What is <code>justify-content: space-between</code> in CSS Grid?</h3>
<p><code>space-between</code> does the following:</p>
<ul>
<li><p>It positions a grid container's first column with its row-start edge.</p>
</li>
<li><p>It positions the container's last column with the row-end edge.</p>
</li>
<li><p>It creates even spacing between each pair of columns between the first and last columns.</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-space-between-illustration-codesweetly.png" alt="Illustration of justify-content's space-between value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's space-between value creates even spacing between each pair of columns between the first and last grid column</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>: grid;
  <span class="hljs-attribute">justify-content</span>: space-between;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <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-ajbrex?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 columns between the first and last grid column.</p>
<h3 id="heading-what-is-justify-content-space-around-in-css-grid">What is <code>justify-content: space-around</code> in CSS Grid?</h3>
<p><code>space-around</code> assigns equal spacing to each side of a grid container's columns.</p>
<p>Therefore, the space before the first column and after the last one is half the width of the space between each pair of columns.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-space-around-illustration-codesweetly.png" alt="Illustration of justify-content's space-around value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's space-around value assigns equal spacing to each side of the grid container's columns</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>: grid;
  <span class="hljs-attribute">justify-content</span>: space-around;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <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-qnla5x?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 grid container's columns.</p>
<h3 id="heading-what-is-justify-content-space-evenly-in-css-grid">What is <code>justify-content: space-evenly</code> in CSS Grid?</h3>
<p><code>space-evenly</code> assigns even spacing to both ends of a grid container and between its columns.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-content-space-evenly-illustration-codesweetly.png" alt="Illustration of justify-content's space-evenly value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-content's space-evenly value assigns even spacing to both ends of the grid container and between its columns</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>: grid;
  <span class="hljs-attribute">justify-content</span>: space-evenly;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">4</span>, <span class="hljs-number">40px</span>);
  <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-vnd1u3?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 grid container and between its columns.</p>
<h2 id="heading-what-is-css-grids-justify-items-property">What Is CSS Grid's <code>justify-items</code> Property?</h2>
<p><strong>justify-items</strong> specifies the default <a target="_blank" href="https://codesweetly.com/css-grid-justify-self-property"><code>justify-self</code></a> value for all the grid items.</p>
<p>The <code>justify-items</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values.</p>
<h3 id="heading-what-is-justify-items-stretch-in-css-grid">What is <code>justify-items: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is <code>justify-items</code>' default value. It stretches the grid container's items to fill their individual cells' row (inline) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-stretch-illustration-codesweetly.png" alt="Illustration of justify-items' stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' stretch value stretches grid items to fill their individual cells' row 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>: grid;
  <span class="hljs-attribute">justify-items</span>: stretch;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-dedmgi?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch the grid items to fill their individual cells' row axis.</p>
<h3 id="heading-what-is-justify-items-start-in-css-grid">What is <code>justify-items: start</code> in CSS Grid?</h3>
<p><code>start</code> positions a grid container's items with the row-start edge of their individual cells' row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-start-illustration-codesweetly.png" alt="Illustration of justify-items' start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' start value positions grid items to their individual cells' row-start edge</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>: grid;
  <span class="hljs-attribute">justify-items</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-zdzwmb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to position the grid items to their individual cells' row-start edge.</p>
<h3 id="heading-what-is-justify-items-center-in-css-grid">What is <code>justify-items: center</code> in CSS Grid?</h3>
<p><code>center</code> positions a grid container's items to the center of their individual cells' row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-center-illustration-codesweetly.png" alt="Illustration of justify-items' center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' center value positions grid items to their individual cells' center</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>: grid;
  <span class="hljs-attribute">justify-items</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-dsgyni?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to position the grid items to the center of their individual cells' row axis.</p>
<h3 id="heading-what-is-justify-items-end-in-css-grid">What is <code>justify-items: end</code> in CSS Grid?</h3>
<p><code>end</code> positions a grid container's items with the row-end edge of their individual cells' row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-items-end-illustration-codesweetly.png" alt="Illustration of justify-items' end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-items' end value positions grid items to their individual cells' row-end edge</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>: grid;
  <span class="hljs-attribute">justify-items</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-pcenzt?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to position the grid items to their individual cells' row-end edge.</p>
<h2 id="heading-what-is-css-grids-align-content-property">What Is CSS Grid's <code>align-content</code> Property?</h2>
<p><strong>align-content</strong> specifies how browsers should align a grid container's rows along the container's column axis.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>A column axis is sometimes called a block axis.</p>
</li>
<li><p>The <code>align-content</code> property works if the total row heights are less than the grid container's height. In other words, you need free space along the container's column axis to align its rows up or down.</p>
</li>
</ul>
<p>The <code>align-content</code> property accepts the following values:</p>
<ul>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
<li><p><code>stretch</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>
<p>Let's discuss these values.</p>
<h3 id="heading-what-is-align-content-start-in-css-grid">What is <code>align-content: start</code> in CSS Grid?</h3>
<p><code>start</code> aligns a grid container's rows with the column-start edge of the grid's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-start-illustration-codesweetly.png" alt="Illustration of align-content's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's start value aligns rows to the grid container's column-start edge</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>: grid;
  <span class="hljs-attribute">align-content</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-cbmgr1?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to align the <code>&lt;section&gt;</code>'s rows to the grid container's column-start edge.</p>
<h3 id="heading-what-is-align-content-center-in-css-grid">What is <code>align-content: center</code> in CSS Grid?</h3>
<p><code>center</code> aligns a grid container's rows to the center of the grid's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-center-illustration-codesweetly.png" alt="Illustration of align-content's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's center value aligns rows to the center of the grid container</em></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">align-content</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-83kj8v?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align the <code>&lt;section&gt;</code>'s rows to the center of the grid container.</p>
<h3 id="heading-what-is-align-content-end-in-css-grid">What is <code>align-content: end</code> in CSS Grid?</h3>
<p><code>end</code> aligns a grid container's rows with the column-end edge of the grid's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-end-illustration-codesweetly.png" alt="Illustration of align-content's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's end value aligns rows to the grid container's column-end edge</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>: grid;
  <span class="hljs-attribute">align-content</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-lc1lus?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to align the <code>&lt;section&gt;</code>'s rows to the grid container's column-end edge.</p>
<h3 id="heading-what-is-align-content-space-between-in-css-grid">What is <code>align-content: space-between</code> in CSS Grid?</h3>
<p><code>space-between</code> does the following:</p>
<ul>
<li><p>It aligns a grid container's first row with its column-start edge.</p>
</li>
<li><p>It aligns the container's last row with the column-end edge.</p>
</li>
<li><p>It creates even spacing between each pair of rows between the first and last row.</p>
</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-space-between-illustration-codesweetly.png" alt="Illustration of align-content's space-between value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's space-between value creates even spacing between each pair of rows between the first and last grid row</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>: grid;
  <span class="hljs-attribute">align-content</span>: space-between;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-ieqvih?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 rows between the first and last grid row.</p>
<h3 id="heading-what-is-align-content-space-around-in-css-grid">What is <code>align-content: space-around</code> in CSS Grid?</h3>
<p><code>space-around</code> assigns equal spacing to each side of a grid container's rows.</p>
<p>Therefore, the space before the first row and after the last one is half the width of the space between each pair of rows.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-space-around-illustration-codesweetly.png" alt="Illustration of align-content's space-around value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's space-around value assigns equal spacing to each side of the grid container's rows</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>: grid;
  <span class="hljs-attribute">align-content</span>: space-around;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-eyzta5?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 grid container's rows.</p>
<h3 id="heading-what-is-align-content-space-evenly-in-css-grid">What is <code>align-content: space-evenly</code> in CSS Grid?</h3>
<p><code>space-evenly</code> assigns even spacing to both ends of a grid container and between its rows.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-content-space-evenly-illustration-codesweetly.png" alt="Illustration of align-content's space-evenly value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-content's space-evenly value assigns even spacing to both ends of the grid container and between its rows</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>: grid;
  <span class="hljs-attribute">align-content</span>: space-evenly;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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-il5vu1?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 grid container and between its rows.</p>
<h2 id="heading-what-is-css-grids-align-items-property">What Is CSS Grid's <code>align-items</code> Property?</h2>
<p><strong>align-items</strong> specifies the default <a target="_blank" href="https://codesweetly.com/css-grid-align-self-property"><code>align-self</code></a> value for all the grid items.</p>
<p>The <code>align-items</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values below.</p>
<h3 id="heading-what-is-align-items-stretch-in-css-grid">What is <code>align-items: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is the default value for <code>align-items</code>. It stretches the grid container's items to fill their individual cells' column (block) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-stretch-illustration-codesweetly.png" alt="Illustration of align-items' stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' stretch value stretches grid items to fill their individual cells' column 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>: grid;
  <span class="hljs-attribute">align-items</span>: stretch;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-fia3ra?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch the grid items to fill their individual cells' column axis.</p>
<h3 id="heading-what-is-align-items-start-in-css-grid">What is <code>align-items: start</code> in CSS Grid?</h3>
<p><code>start</code> aligns a grid container's items with the column-start edge of their individual cells' column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-start-illustration-codesweetly.png" alt="Illustration of align-items' start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' start value aligns grid items to their individual cells' column-start edge</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>: grid;
  <span class="hljs-attribute">align-items</span>: start;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-achetg?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to align the grid items to their individual cells' column-start edge.</p>
<h3 id="heading-what-is-align-items-center-in-css-grid">What is <code>align-items: center</code> in CSS Grid?</h3>
<p><code>center</code> aligns a grid container's items to the center of their individual cells' column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-center-illustration-codesweetly.png" alt="Illustration of align-items' center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' center value aligns grid items to their individual cells' center</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>: grid;
  <span class="hljs-attribute">align-items</span>: center;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cmqydk?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align the grid items to the center of their individual cells' column axis.</p>
<h3 id="heading-what-is-align-items-end-in-css-grid">What is <code>align-items: end</code> in CSS Grid?</h3>
<p><code>end</code> aligns a grid container's items with the column-end edge of their individual cells' column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-items-end-illustration-codesweetly.png" alt="Illustration of align-items' end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-items' end value aligns grid items to their individual cells' column-end edge</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>: grid;
  <span class="hljs-attribute">align-items</span>: end;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <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">400px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-jei1qv?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to align the grid items to their individual cells' column-end edge.</p>
<p>So, now that we know the types of CSS grid container properties, we can discuss the grid item properties.</p>
<h2 id="heading-what-are-the-grid-items-properties">What Are the Grid Item's Properties?</h2>
<p>A grid item's properties specify how browsers should layout a specified item within the grid box model.</p>
<p><strong>Note:</strong> We define a grid item's property on the item, not its container.</p>
<p>The ten (10) types of grid item properties are:</p>
<ul>
<li><p><code>justify-self</code></p>
</li>
<li><p><code>align-self</code></p>
</li>
<li><p><code>grid-column-start</code></p>
</li>
<li><p><code>grid-column-end</code></p>
</li>
<li><p><code>grid-column</code></p>
</li>
<li><p><code>grid-row-start</code></p>
</li>
<li><p><code>grid-row-end</code></p>
</li>
<li><p><code>grid-row</code></p>
</li>
<li><p><code>grid-area</code></p>
</li>
<li><p><code>grid-template-areas</code></p>
</li>
</ul>
<p>Let's discuss the ten types now.</p>
<h2 id="heading-what-is-css-grids-justify-self-property">What Is CSS Grid's <code>justify-self</code> Property?</h2>
<p><strong>justify-self</strong> specifies how browsers should position the selected grid item along its cell's row (inline) axis.</p>
<p>The <code>justify-self</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values.</p>
<h3 id="heading-what-is-justify-self-stretch-in-css-grid">What is <code>justify-self: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is <code>justify-self</code>'s default value. It stretches the selected grid item to fill its cell's row (inline) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-stretch-illustration-codesweetly.png" alt="Illustration of justify-self's stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's stretch value stretches the selected grid item to fill its cell's row axis</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: stretch;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-82a3ep?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch <code>grid-item1</code> to fill its cell's row axis.</p>
<h3 id="heading-what-is-justify-self-start-in-css-grid">What is <code>justify-self: start</code> in CSS Grid?</h3>
<p><code>start</code> positions the selected grid item with the row-start edge of its cell's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-start-illustration-codesweetly.png" alt="Illustration of justify-self's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's start value positions the selected grid item to its cell's row-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: start;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-cnz92l?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to position <code>grid-item1</code> to its cell's row-start edge.</p>
<h3 id="heading-what-is-justify-self-center-in-css-grid">What is <code>justify-self: center</code> in CSS Grid?</h3>
<p><code>center</code> positions the selected grid item to the center of its cell's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-center-illustration-codesweetly.png" alt="Illustration of justify-self's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's center value positions the selected grid item to its cell's center</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: center;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-9kspmx?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to position <code>grid-item1</code> to its cell's center.</p>
<h3 id="heading-what-is-justify-self-end-in-css-grid">What is <code>justify-self: end</code> in CSS Grid?</h3>
<p><code>end</code> positions the selected grid item with the row-end edge of its cell's row axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-justify-self-end-illustration-codesweetly.png" alt="Illustration of justify-self's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>justify-self's end value positions the selected grid item to its cell's row-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">justify-self</span>: end;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-xschhb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to position <code>grid-item1</code> to its cell's row-end edge.</p>
<h2 id="heading-what-is-css-grids-align-self-property">What Is CSS Grid's <code>align-self</code> Property?</h2>
<p><strong>align-self</strong> specifies how browsers should align the selected grid item along its cell's column (block) axis.</p>
<p>The <code>align-self</code> property accepts the following values:</p>
<ul>
<li><p><code>stretch</code></p>
</li>
<li><p><code>start</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>end</code></p>
</li>
</ul>
<p>Let's discuss the four values below.</p>
<h3 id="heading-what-is-align-self-stretch-in-css-grid">What is <code>align-self: stretch</code> in CSS Grid?</h3>
<p><code>stretch</code> is <code>align-self</code>'s default value. It stretches the selected grid item to fill its cell's column (block) axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-stretch-illustration-codesweetly-1.png" alt="Illustration of align-self's stretch value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's stretch value stretches the selected grid item to fill its cell's column axis</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: stretch;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-unnbb9?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>stretch</code> value to stretch <code>grid-item1</code> to fill its cell's column axis.</p>
<h3 id="heading-what-is-align-self-start-in-css-grid">What is <code>align-self: start</code> in CSS Grid?</h3>
<p><code>start</code> aligns the selected grid item with the column-start edge of its cell's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-start-illustration-codesweetly-1.png" alt="Illustration of align-self's start value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's start value aligns the selected grid item to its cell's column-start edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: start;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ytttz4?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>start</code> value to align <code>grid-item1</code> to its cell's column-start edge.</p>
<h3 id="heading-what-is-align-self-center-in-css-grid">What is <code>align-self: center</code> in CSS Grid?</h3>
<p><code>center</code> aligns the selected grid item to the center of its cell's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-center-illustration-codesweetly.png" alt="Illustration of align-self's center value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's center value aligns the selected grid item to its cell's center</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: center;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-fpv4ed?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>center</code> value to align <code>grid-item1</code> to its cell's center.</p>
<h3 id="heading-what-is-align-self-end-in-css-grid">What is <code>align-self: end</code> in CSS Grid?</h3>
<p><code>end</code> aligns the selected grid item with the column-end edge of its cell's column axis.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-align-self-end-illustration-codesweetly.png" alt="Illustration of align-self's end value in CSS Grid" width="600" height="400" loading="lazy"></p>
<p><em>align-self's end value aligns the selected grid item to its cell's column-end edge</em></p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">align-self</span>: end;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-vvmwzv?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>end</code> value to align grid-item1 to its cell's column-end edge.</p>
<h2 id="heading-what-is-css-grids-grid-column-start-property">What Is CSS Grid's <code>grid-column-start</code> Property?</h2>
<p><strong>grid-column-start</strong> specifies where the selected grid item should start (or span) along the grid container's row (inline) axis.</p>
<p>The <code>grid-column-start</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;column-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-columns&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-start-the-selected-grid-item-following-the-normal-column-flow">Example 1: How to auto-start the selected grid item following the normal column flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-rvhhxh?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-start <code>grid-item1</code> according to the normal column layout flow.</p>
<h3 id="heading-example-2-how-to-start-the-selected-grid-item-at-column-line-3">Example 2: How to start the selected grid item at column line 3</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-ep6zgd?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-column-start</code> property to start <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">column line</a> 3.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-two-columns">Example 3: How to span the selected grid item across two columns</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-w1nw8k?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 2</code> value to span <code>grid-item1</code> across two columns.</p>
<h2 id="heading-what-is-css-grids-grid-column-end-property">What Is CSS Grid's <code>grid-column-end</code> Property?</h2>
<p><strong>grid-column-end</strong> specifies where the selected grid item should end (or span) along the grid container's row (inline) axis.</p>
<p>The <code>grid-column-end</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;column-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-columns&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-end-the-selected-grid-item-following-the-normal-column-flow">Example 1: How to auto-end the selected grid item following the normal column flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-end</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-1mmxhp?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-end <code>grid-item1</code> according to the normal layout flow.</p>
<h3 id="heading-example-2-how-to-end-the-selected-grid-item-at-column-line-3">Example 2: How to end the selected grid item at column line 3</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column-end</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-hjcfhc?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-column-end</code> property to end <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">column line</a> 3.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-two-columns-1">Example 3: How to span the selected grid item across two columns</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">2</span>;
  <span class="hljs-attribute">grid-column-end</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-yhe3ew?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 2</code> value to span <code>grid-item1</code> across two columns.</p>
<h2 id="heading-what-is-css-grids-grid-column-property">What Is CSS Grid's <code>grid-column</code> Property?</h2>
<p><strong>grid-column</strong> is a shorthand for the <code>grid-column-start</code> and <code>grid-column-end</code> properties.</p>
<p>In other words, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column-end</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p>You can alternatively use the <code>grid-column</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / <span class="hljs-number">3</span>;
}
</code></pre>
<p><strong>Here is grid-column's syntax:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-column</span>: <span class="hljs-selector-tag">grid-column-start</span> / <span class="hljs-selector-tag">grid-column-end</span>;
</code></pre>
<h2 id="heading-what-is-css-grids-grid-row-start-property">What Is CSS Grid's <code>grid-row-start</code> Property?</h2>
<p><strong>grid-row-start</strong> specifies where the selected grid item should start (or span) along the grid container's column (block) axis.</p>
<p>The <code>grid-row-start</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;row-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-rows&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-start-the-selected-grid-item-following-the-normal-row-flow">Example 1: How to auto-start the selected grid item following the normal row flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-qthpn6?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-start <code>grid-item1</code> according to the normal row layout flow.</p>
<h3 id="heading-example-2-how-to-start-the-selected-grid-item-at-row-line-3">Example 2: How to start the selected grid item at row line 3</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-phrjcb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-row-start</code> property to start <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">row line</a> 3.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-two-rows">Example 3: How to span the selected grid item across two rows</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-5bchie?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 2</code> value to span <code>grid-item1</code> across two rows.</p>
<h2 id="heading-what-is-css-grids-grid-row-end-property">What Is CSS Grid's <code>grid-row-end</code> Property?</h2>
<p><strong>grid-row-end</strong> specifies where the selected grid item should end (or span) along the grid container's column (block) axis.</p>
<p>The <code>grid-row-end</code> property accepts the following values:</p>
<ul>
<li><p><code>auto</code></p>
</li>
<li><p><code>&lt;column-line-number&gt;</code></p>
</li>
<li><p><code>span &lt;number-of-columns&gt;</code></p>
</li>
</ul>
<h3 id="heading-example-1-how-to-auto-end-the-selected-grid-item-following-the-normal-row-flow">Example 1: How to auto-end the selected grid item following the normal row flow</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-end</span>: auto;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-w1rpy8?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>auto</code> value to auto-end <code>grid-item1</code> according to the normal row layout flow.</p>
<h3 id="heading-example-2-how-to-end-the-selected-grid-item-at-row-line-5">Example 2: How to end the selected grid item at row line 5</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-row-end</span>: <span class="hljs-number">5</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-wps8a3?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-row-end</code> property to end <code>grid-item1</code> at <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">row line</a> 5.</p>
<h3 id="heading-example-3-how-to-span-the-selected-grid-item-across-three-rows">Example 3: How to span the selected grid item across three rows</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-end</span>: span <span class="hljs-number">3</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-skcbxf?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>span 3</code> value to span <code>grid-item1</code> across three rows.</p>
<h2 id="heading-what-is-css-grids-grid-row-property">What Is CSS Grid's <code>grid-row</code> Property?</h2>
<p><strong>grid-row</strong> is a shorthand for the <code>grid-row-start</code> and <code>grid-row-end</code> properties.</p>
<p>In other words, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-row-end</span>: <span class="hljs-number">5</span>;
}
</code></pre>
<p>You can alternatively use the <code>grid-row</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">1</span> / <span class="hljs-number">5</span>;
}
</code></pre>
<p><strong>Here is grid-row's syntax:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-row</span>: <span class="hljs-selector-tag">grid-row-start</span> / <span class="hljs-selector-tag">grid-row-end</span>;
</code></pre>
<h2 id="heading-what-is-css-grids-grid-area-property">What Is CSS Grid's <code>grid-area</code> Property?</h2>
<p>You can use the <strong>grid-area</strong> property for the following purposes:</p>
<ol>
<li><p>As a shorthand for the <code>grid-column-start</code>, <code>grid-column-end</code>, <code>grid-row-start</code>, and <code>grid-row-end</code> properties.</p>
</li>
<li><p>To specify a grid item's name.</p>
</li>
</ol>
<p>Let's discuss the two purposes below.</p>
<h3 id="heading-how-to-use-grid-area-as-a-shorthand">How to use <code>grid-area</code> as a shorthand</h3>
<p>Here is the syntax for using the <code>grid-area</code> property as a shorthand for the <code>grid-column-start</code>, <code>grid-column-end</code>, <code>grid-row-start</code>, and <code>grid-row-end</code> properties:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.your-grid-item</span> {
  <span class="hljs-attribute">grid-area</span>: grid-row-start / grid-column-start / grid-row-end / grid-column-end;
}
</code></pre>
<p>Therefore, instead of writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-row-start</span>: <span class="hljs-number">3</span>;
  <span class="hljs-attribute">grid-row-end</span>: <span class="hljs-number">5</span>;
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">1</span>;
  <span class="hljs-attribute">grid-column-end</span>: span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-sqkxmk?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>You can alternatively use the <code>grid-area</code> property to shorten your code like so:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: <span class="hljs-number">3</span> / <span class="hljs-number">1</span> / <span class="hljs-number">5</span> / span <span class="hljs-number">2</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-42swnh?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<h3 id="heading-how-to-use-grid-area-to-specify-a-grid-items-name">How to use <code>grid-area</code> to specify a grid item's name</h3>
<p>Here is the syntax for using the <code>grid-area</code> property to specify a grid item's name:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.your-grid-item</span> {
  <span class="hljs-attribute">grid-area</span>: item-name;
}
</code></pre>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: firstDiv;
}

<span class="hljs-selector-class">.grid-item2</span> {
  <span class="hljs-attribute">grid-area</span>: middleDiv;
}

<span class="hljs-selector-class">.grid-item2</span> {
  <span class="hljs-attribute">grid-area</span>: lastDiv;
}
</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">"grid-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">"grid-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">"grid-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">section</span>&gt;</span>
</code></pre>
<p>Using <code>grid-area</code> to define a named grid item allows your grid container's <code>grid-template-areas</code> property to use the name to set the item's size and location.</p>
<h2 id="heading-what-is-css-grids-grid-template-areas-property">What Is CSS Grid's <code>grid-template-areas</code> Property?</h2>
<p><strong>grid-template-areas</strong> specifies the area where you want to place <em>named grid items</em> within a grid container.</p>
<p><strong>Remember:</strong> We use the CSS <code>[grid-area](#heading-how-to-use-grid-area-to-specify-a-grid-items-name)</code> property to name grid items.</p>
<h3 id="heading-example-1-how-to-place-a-named-grid-item-across-three-columns">Example 1: How to place a named grid item across three columns</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: firstDiv;
}

<span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-areas</span>: <span class="hljs-string">"firstDiv firstDiv firstDiv . ."</span>;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-1sw8ww?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-areas</code> property to place <code>grid-item1</code> across the first three column areas.</p>
<p><strong>Note the following:</strong></p>
<ul>
<li><p>Quotation marks (<code>""</code>) define each grid row.</p>
</li>
<li><p>A period symbol (<code>.</code>) defines an unnamed grid item.</p>
</li>
<li><p>We used the whitespace character to separate grid columns.</p>
</li>
</ul>
<h3 id="heading-example-2-how-to-specify-multiple-named-grid-items-placements">Example 2: How to specify multiple named grid items' placements</h3>
<pre><code class="lang-css"><span class="hljs-selector-class">.grid-item1</span> {
  <span class="hljs-attribute">grid-area</span>: header;
}

<span class="hljs-selector-class">.grid-item2</span> {
  <span class="hljs-attribute">grid-area</span>: article;
}

<span class="hljs-selector-class">.grid-item3</span> {
  <span class="hljs-attribute">grid-area</span>: footer;
}

<span class="hljs-selector-class">.grid-item4</span> {
  <span class="hljs-attribute">grid-area</span>: sidebar;
}

<span class="hljs-selector-class">.grid-item5</span> {
  <span class="hljs-attribute">grid-area</span>: ads1;
}

<span class="hljs-selector-class">.grid-item6</span> {
  <span class="hljs-attribute">grid-area</span>: ads2;
}

<span class="hljs-selector-class">.grid-item7</span> {
  <span class="hljs-attribute">grid-area</span>: ads3;
}

<span class="hljs-selector-tag">section</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">5</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">7</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-areas</span>:
    <span class="hljs-string">"header header header header header"</span>
    <span class="hljs-string">"sidebar article article article ads1"</span>
    <span class="hljs-string">"sidebar article article article ads1"</span>
    <span class="hljs-string">"sidebar article article article ads1"</span>
    <span class="hljs-string">"sidebar article article article ads2"</span>
    <span class="hljs-string">"sidebar article article article ads3"</span>
    <span class="hljs-string">"sidebar footer footer footer footer"</span>;
  <span class="hljs-attribute">background-color</span>: orange;
  <span class="hljs-attribute">margin</span>: <span class="hljs-number">30px</span>;
}
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-9b5emj?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>grid-template-areas</code> property to specify where browsers should place the grid items across the rows and columns of the grid container.</p>
<h3 id="heading-important-stuff-to-know-about-the-grid-template-areas-property">Important Stuff to Know about the <code>grid-template-areas</code> Property</h3>
<p>Here are four essential facts to remember when using the <code>grid-template-areas</code> property:</p>
<h4 id="heading-1-grid-template-areas-do-not-permit-empty-cells">1. <code>grid-template-areas</code> do not permit empty cells</h4>
<p>The <code>grid-template-areas</code> property requires you to provide an item for all grid cells.</p>
<p>For instance, consider this snippet:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>";
</code></pre>
<p>Above is an invalid <code>grid-template-areas</code> value because the first row is incomplete.</p>
<p>In other words, the first row is the only one with two columns. However, <code>grid-template-areas</code> expect all the rows in a grid container to have the same number of columns.</p>
<h4 id="heading-2-you-can-use-dots-to-specify-empty-cells">2. You can use dots to specify empty cells</h4>
<p>Suppose you wish to leave some cells empty. In that case, use a dot (<code>.</code>) or multiple unspaced dots (<code>....</code>).</p>
<p><strong>Here's an example:</strong></p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> . . ."
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>";
</code></pre>
<p><a target="_blank" href="https://stackblitz.com/edit/js-yfhx4g?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the three <em>spaced</em> dot (<code>.</code>) symbols to indicate three empty cells.</p>
<h4 id="heading-3-grid-template-areas-do-not-permit-placing-an-item-in-multiple-locations">3. <code>grid-template-areas</code> do not permit placing an item in multiple locations</h4>
<p>The <code>grid-template-areas</code> property cannot place items twice within a grid container.</p>
<p>For instance, consider this snippet:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>";
</code></pre>
<p>Above is an invalid <code>grid-template-areas</code> value because the <code>header</code> item occupies two grid areas.</p>
<h4 id="heading-4-grid-template-areas-allows-rectangular-areas-only">4. <code>grid-template-areas</code> allows rectangular areas only</h4>
<p>The <code>grid-template-areas</code> property cannot create non-rectangular areas (such as T-shaped or L-shaped).</p>
<p>For instance, consider this snippet:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-areas</span>:
  "<span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">header</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">ads1</span> <span class="hljs-selector-tag">ads1</span> <span class="hljs-selector-tag">ads1</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads1</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads2</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">article</span> <span class="hljs-selector-tag">ads3</span>"
  "<span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">footer</span>";
</code></pre>
<p>Above is an invalid <code>grid-template-areas</code> value because the <code>ads1</code> item creates a non-rectangular grid area.</p>
<p>So, now that we know the types of CSS grid item properties, we can discuss how to define minimum and maximum grid sizes.</p>
<h2 id="heading-how-to-use-the-css-minmax-function-to-define-minimum-and-maximum-grid-sizes">How to Use the CSS <code>minmax()</code> function to Define Minimum and Maximum Grid Sizes</h2>
<p><strong>minmax()</strong> is a CSS Grid function for defining minimum and maximum grid sizes.</p>
<h3 id="heading-syntax-of-the-css-minmax-function">Syntax of the CSS <code>minmax()</code> function</h3>
<p><code>minmax()</code> accepts two arguments. Here is the syntax:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">minmax</span>(<span class="hljs-selector-tag">minimum-size</span>, <span class="hljs-selector-tag">maximum-size</span>)
</code></pre>
<p><strong>Note the following:</strong></p>
<ul>
<li><p>The <code>minimum-size</code> argument specifies the smallest size for a specific length.</p>
</li>
<li><p>The <code>maximum-size</code> argument specifies the largest size for a specific length.</p>
</li>
<li><p><code>minmax()</code>'s arguments can be any of the non-negative <a target="_blank" href="https://codesweetly.com/css-unit">CSS lengths</a>, or any one of the keywords <code>auto</code>, <code>min-content</code>, or <code>max-content</code>.</p>
</li>
<li><p>Suppose the <code>maximum-size</code> argument is less than the <code>minimum-size</code>. In that case, browsers will ignore the <code>maximum-size</code> and treat the <code>minmax()</code> function as <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/min"><code>min()</code></a>.</p>
</li>
<li><p>An <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> unit</a> is an _in_valid unit for the <code>minimum-size</code> argument.</p>
</li>
</ul>
<h3 id="heading-how-to-use-the-css-minmax-function">How to use the CSS <code>minmax()</code> function</h3>
<p>You can use the <code>minmax()</code> function as a value for the following CSS properties:</p>
<ul>
<li><p><code>grid-template-columns</code></p>
</li>
<li><p><code>grid-template-rows</code></p>
</li>
<li><p><code>grid-auto-columns</code></p>
</li>
<li><p><code>grid-auto-rows</code></p>
</li>
</ul>
<h3 id="heading-examples-of-the-css-minmax-function">Examples of the CSS <code>minmax()</code> function</h3>
<p>Below are examples of how the CSS <code>minmax()</code> function works.</p>
<h4 id="heading-how-to-define-a-70px-minimum-and-a-250px-maximum-row-grid-size">How to define a <code>70px</code> minimum and a <code>250px</code> maximum row grid size</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">50px</span> <span class="hljs-number">100px</span> <span class="hljs-built_in">minmax</span>(<span class="hljs-number">70px</span>, <span class="hljs-number">250px</span>);
  <span class="hljs-attribute">grid-template-columns</span>: auto auto auto;
  <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-giarya?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the CSS <code>minmax()</code> function to set the <code>&lt;section&gt;</code>'s third row's height to a minimum of <code>70px</code> and a maximum of <code>250px</code>.</p>
<h4 id="heading-how-to-define-a-30-minimum-and-a-70-maximum-column-grid-size">How to define a <code>30%</code> minimum and a <code>70%</code> maximum column grid size</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-rows</span>: auto auto auto;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-built_in">minmax</span>(<span class="hljs-number">30%</span>, <span class="hljs-number">70%</span>) <span class="hljs-number">1</span>fr;
  <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-ekn23p?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>We used the CSS <code>minmax()</code> function to set the <code>&lt;section&gt;</code>'s second column's width to a minimum of <code>30%</code> and a maximum of <code>70%</code>.</p>
<p><strong>Note:</strong> You can use the CSS <code>repeat()</code> function to specify <code>grid-template-rows</code> or <code>grid-template-columns</code> values with repeated patterns. Let's discuss the <code>repeat()</code> function now.</p>
<h2 id="heading-how-to-use-the-css-repeat-function-to-define-grid-tracks-with-repeated-patterns">How to Use the CSS <code>repeat()</code> Function to Define Grid Tracks with Repeated Patterns</h2>
<p>The <strong>repeat()</strong> CSS function allows you to write more concise and readable values when specifying multiple <a target="_blank" href="https://codesweetly.com/css-grid-lines-explained">grid tracks</a> with repeated patterns.</p>
<p><strong>Note:</strong></p>
<ul>
<li><p>A track refers to a grid container's column (or row).</p>
</li>
<li><p>You can use <code>repeat()</code> as a value for the CSS <code>grid-template-columns</code> or <code>grid-template-rows</code> properties.</p>
</li>
</ul>
<h3 id="heading-syntax-of-the-css-repeat-function">Syntax of the CSS <code>repeat()</code> function</h3>
<p><code>repeat()</code> accepts two arguments. Here is the syntax:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">repeat</span>(<span class="hljs-selector-tag">number-of-repetition</span>, <span class="hljs-selector-tag">track-list-to-repeat</span>)
</code></pre>
<h3 id="heading-argument-1-number-of-repetition">Argument 1: <code>number-of-repetition</code></h3>
<p>The <code>number-of-repetition</code> argument specifies the number of times browsers should repeat the specified track list (the second argument).</p>
<p>The <code>number-of-repetition</code> argument can be any of the following values:</p>
<ul>
<li><p>Number <code>1</code> or its multiple</p>
</li>
<li><p><code>auto-fill</code></p>
</li>
<li><p><code>auto-fit</code></p>
</li>
</ul>
<h4 id="heading-auto-fill-vs-auto-fit-whats-the-difference"><code>auto-fill</code> vs. <code>auto-fit</code>: What's the difference?</h4>
<p>The <code>auto-fill</code> and <code>auto-fit</code> values automatically create as many tracks as needed to fill a grid container without causing an overflow.</p>
<p>The difference between the two values is that <code>auto-fit</code> collapses empty tracks to zero-pixel (<code>0px</code>). But <code>auto-fill</code> displays both empty and filled tracks.</p>
<p><strong>Note:</strong> Empty tracks are columns or rows with no grid item.</p>
<h3 id="heading-argument-2-track-list-to-repeat">Argument 2: <code>track-list-to-repeat</code></h3>
<p>The <code>track-list-to-repeat</code> argument specifies the track pattern you wish to repeat across a grid container's horizontal or vertical axis.</p>
<p>In other words, <code>track-list-to-repeat</code> consists of one or more values specifying the sizes of tracks browsers should repeat within a grid container.</p>
<p><strong>Note:</strong> Suppose your <code>number-of-repetition</code> is <code>auto-fill</code> or <code>auto-fit</code>. In that case, you can use only <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/repeat#fixed-size">fixed sizes</a> as the <code>track-list-to-repeat</code> argument.</p>
<h3 id="heading-examples-of-the-css-repeat-function">Examples of the CSS <code>repeat()</code> function</h3>
<p>Below are examples of how the CSS <code>repeat()</code> function works.</p>
<h4 id="heading-how-to-create-a-three-column-grid-container-with-70px-column-widths">How to create a three-column grid container with <code>70px</code> column-widths</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</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">70px</span>);
  <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-imfqcm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to create three <code>70px</code>-wide columns.</p>
<p>Below is the non-<code>repeat()</code> equivalent of the above <code>grid-template-columns</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 70<span class="hljs-selector-tag">px</span> 70<span class="hljs-selector-tag">px</span> 70<span class="hljs-selector-tag">px</span>;
</code></pre>
<h4 id="heading-how-to-create-a-four-column-grid-container-with-one-50px-and-three-90px-column-widths">How to create a four-column grid container with one <code>50px</code> and three <code>90px</code> column-widths</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">50px</span> <span class="hljs-built_in">repeat</span>(<span class="hljs-number">3</span>, <span class="hljs-number">90px</span>);
  <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-bgdk3a?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to create three <code>90px</code>-wide columns.</p>
<p>Below is the non-<code>repeat()</code> equivalent of the above <code>grid-template-columns</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 50<span class="hljs-selector-tag">px</span> 90<span class="hljs-selector-tag">px</span> 90<span class="hljs-selector-tag">px</span> 90<span class="hljs-selector-tag">px</span>;
</code></pre>
<h4 id="heading-how-to-create-a-five-column-grid-container-with-one-40px-and-two-60px-1fr-column-widths">How to create a five-column grid container with one <code>40px</code> and two <code>60px 1fr</code> column-widths</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">40px</span> <span class="hljs-built_in">repeat</span>(<span class="hljs-number">2</span>, <span class="hljs-number">60px</span> <span class="hljs-number">1</span>fr);
  <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-wjgjym?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to create two <code>60px 1fr</code>-wide columns.</p>
<p>Below is the non-<code>repeat()</code> equivalent of the above <code>grid-template-columns</code> property:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span>: 40<span class="hljs-selector-tag">px</span> 60<span class="hljs-selector-tag">px</span> 1<span class="hljs-selector-tag">fr</span> 60<span class="hljs-selector-tag">px</span> 1<span class="hljs-selector-tag">fr</span>;
</code></pre>
<p><strong>Note:</strong> We used the <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr"><code>fr</code> (fraction) unit</a> to scale the third and fifth columns relative to the fraction of available space in the grid container.</p>
<h4 id="heading-how-to-auto-fill-the-grid-container-with-70px-wide-columns">How to auto-fill the grid container with <code>70px</code>-wide columns</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, <span class="hljs-number">70px</span>);
  <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-bwdeeb?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> function to automatically fill the grid container with <code>70px</code>-wide columns.</p>
<h4 id="heading-how-to-auto-fill-the-grid-container-with-a-minimum-of-50px-and-a-maximum-of-1fr-wide-columns">How to auto-fill the grid container with a minimum of <code>50px</code> and a maximum of <code>1fr</code> wide columns</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">50px</span>, <span class="hljs-number">1</span>fr));
  <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-hrof4i?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the CSS <code>repeat()</code> and <code>minmax()</code> functions to automatically fill the grid container with a minimum of <code>50px</code>-wide columns and a maximum of <code>1fr</code>.</p>
<p><strong>Note:</strong> <code>1fr</code> means one <a target="_blank" href="https://codesweetly.com/css-unit#fraction-fr">fraction unit</a>.</p>
<h4 id="heading-how-to-auto-fit-the-grid-container-with-a-minimum-of-50px-and-a-maximum-of-1fr-wide-columns">How to auto-fit the grid container with a minimum of <code>50px</code> and a maximum of <code>1fr</code> wide columns</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">section</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fit, minmax(<span class="hljs-number">50px</span>, <span class="hljs-number">1</span>fr));
  <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-pveewm?file=style.css"><strong>Try it on StackBlitz</strong></a></p>
<p>The snippet above used the <code>CSS repeat()</code> and <code>minmax()</code> functions to automatically fit the grid container with a minimum of <code>50px</code>-wide columns and a maximum of <code>1fr</code>.</p>
<h2 id="heading-overview">Overview</h2>
<p>In this article, we discussed all the CSS Grid tools you need to create basic and advanced website layouts in responsive ways that look great on all devices.</p>
<p>I hope you've found this article helpful.</p>
<h3 id="heading-thanks-for-reading">Thanks for reading!</h3>
<p>If you like this tutorial, you can <a target="_blank" href="https://amzn.to/42s5KXZ">get the guidebook version at Amazon</a>. It is a handy quick reference guide to CSS Grid.</p>
<p><a target="_blank" href="https://amzn.to/42s5KXZ"><img src="https://www.freecodecamp.org/news/content/images/2023/03/css-grid-book-codesweetly.png" alt="Buy the CSS Grid Guidebook 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[ How to Use CSS Grid Layout – Grid Properties Explained with Examples ]]>
                </title>
                <description>
                    <![CDATA[ Have you ever had a problem positioning items on your web browser? Perhaps every time you try to think of a solution, you become tired and give up. If so, stay tuned as I reveal a new method for resolving these kinds of problems with minimal or no st... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-css-grid-layout/</link>
                <guid isPermaLink="false">66d45e0a182810487e0ce139</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Okoro Emmanuel Nzube ]]>
                </dc:creator>
                <pubDate>Wed, 25 May 2022 15:32:31 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/CSS-GRID-3.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Have you ever had a problem positioning items on your web browser? Perhaps every time you try to think of a solution, you become tired and give up.</p>
<p>If so, stay tuned as I reveal a new method for resolving these kinds of problems with minimal or no stress.</p>
<p>Welcome everyone. In this tutorial, we'll go through how to use the CSS grid layout.</p>
<p>First we'll learn what CSS Grid is and what it's meant to do. Then we'll go through the features of CSS grid, reasons why we should study it, and the benefits it brings to our projects. Finally, we'll discuss when it's best to use it.</p>
<h2 id="heading-what-is-css-grid">What is CSS Grid?</h2>
<p>So what is CSS Grid?</p>
<p>CSS Grid is a two-dimensional layout that you can use for creating responsive items on the web. The Grid items are arranged in columns, and you can easily position rows without having to mess around with the HTML code.</p>
<p>Here is a concise definition of the CSS Grid layout:</p>
<blockquote>
<p>CSS Grid is a powerful tool that allows for two-dimensional layouts for columns and rows to be created on the web. (<a target="_blank" href="https://learncssgrid.com/">Source</a>)</p>
</blockquote>
<h2 id="heading-features-of-css-grid-layout">Features of CSS Grid Layout</h2>
<h3 id="heading-flexible-track-sizes">Flexible Track Sizes</h3>
<p>You can use the <code>fr</code> unit (Fraction Unit) to assign any specified pixel value to the grid. This will make your grid organized and responsive.</p>
<h3 id="heading-item-placement">Item Placement</h3>
<p>CSS grid has made it much easier to position items in the container in any area you want them to be without having to mess with the HTML markup.</p>
<h3 id="heading-alignment-controls">Alignment Controls</h3>
<p>The alignment of an element/item in a container is easier than ever before with CSS Grid. In the container, you can now arrange elements/items horizontally and vertically as you wish.</p>
<h2 id="heading-benefits-of-css-grid">Benefits of CSS Grid</h2>
<p>CSS Grid is very flexible and responsive. It makes it easy to create two-dimensional layouts. CSS Grid also easy to use and is supported by most web browsers.</p>
<p>The CSS grid makes your mark-up cleaner (in your HTML code) and gives you a lot more flexibility. This is partly because you don’t have to change the mark-up (HTML code) to change the position of an item using the CSS grid.</p>
<p>All in all, CSS Grid Layout helps us build a more complex layouts using both columns and rows.</p>
<h2 id="heading-when-should-you-use-css-grid">When Should You Use CSS Grid</h2>
<p>Although you can use CSS Grid in practically any aspect of web development, there are certain situations when it's ideal.</p>
<p>For example, when we have a complex design layout to implement, CSS Grid is better than the CSS float property. This is because Grid is a two-dimensional layout (with columns <strong>and</strong> rows), whereas the CSS float property is a one-dimensional layout (with columns <strong>or</strong> rows).</p>
<p>Grid is also a good choice when we need a space or gap between elements. By using the CSS grid <code>gap</code> property, the spacing of two elements is much easier than using the CSS <code>margin</code> and <code>padding</code> properties which might end up complicating things.</p>
<h2 id="heading-css-grid-properties">CSS Grid Properties</h2>
<p>The CSS grid layout consists of many grid properties. Now we'll take a look at some of them so we can learn how to use them.</p>
<h3 id="heading-grid-container-property">Grid container property</h3>
<p>This is a CSS grid property that houses the grid items/elements. We implement the CSS grid container property by setting the container to a <code>display</code> property of <code>grid</code> or <code>in-line grid</code>.</p>
<p>For Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">grid</span>;
</code></pre>
<p>or</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">display</span>: <span class="hljs-selector-tag">in-line</span> <span class="hljs-selector-tag">grid</span>;
</code></pre>
<h3 id="heading-grid-template-column-property">Grid-template-column property</h3>
<p>This is a property used to set each column’s width. It can also define how many columns you want to set to your project.</p>
<p>You can implement the CSS gird column property using <code>grid-template-column</code>.</p>
<p>For Example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-column</span>: 100<span class="hljs-selector-tag">px</span> <span class="hljs-selector-tag">auto</span> 100<span class="hljs-selector-tag">px</span>;
</code></pre>
<p>The code above shows that we have three columns. The width of columns one (the first column) and three (the third column) are set to <code>100px</code>. The width of column two (the middle column) is set to <code>auto</code>.</p>
<p>This means that as the size of your screen increases, columns one and three take <code>100px</code> of the screen width, while column two takes the remaining width of the screen (which is <code>auto</code>).</p>
<h3 id="heading-grid-template-row-property">Grid-template-row property</h3>
<p>You use the CSS row property to set the height of each column. You can also use it to define how many rows you want to set in your project.</p>
<p>You can implement the CSS gird row property using <code>grid-template-row</code>, like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-row</span>: 50<span class="hljs-selector-tag">px</span> 50<span class="hljs-selector-tag">px</span>;
</code></pre>
<p>The code above shows that we have a total of two rows and those two rows are <code>50px</code> high.</p>
<p>Note that we can also assign the column and row property to our HTML code at once by simply using <code>gird-template</code>. <code>Grid-template</code> is another way of representing the <code>grid-template column</code> and <code>grid-template-row</code>.</p>
<p>For example:</p>
<pre><code class="lang-css"> <span class="hljs-selector-tag">grid-template</span>: 50<span class="hljs-selector-tag">px</span> 50<span class="hljs-selector-tag">px</span> / 100<span class="hljs-selector-tag">px</span> <span class="hljs-selector-tag">auto</span> 100<span class="hljs-selector-tag">px</span>;
</code></pre>
<p>The code above will give you the same result as <code>grid-template-column</code> and <code>grid-template-row</code>.</p>
<p>To use the <code>grid-template</code> property, you will have to assign the value to the row first before assigning the column's value, just like the code above. The <code>50px 50px</code> is for the row while <code>100px auto 100px</code> is for the column.</p>
<p>A way to remember this is by thinking of the letter L:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-90.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>grid-template</em></p>
<p>Try this out and see it for yourself.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/CSS-GRID-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>A gird with a column of 100px auto 100px and row of 50px 50px</em></p>
<h3 id="heading-column-gap-property">Column-gap property</h3>
<p>As the name states, it is a grid property that assigns a space between two or more columns in a container. You can do this by using the <code>column-gap</code> property and giving it a value. For example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">column-gap</span>: 20<span class="hljs-selector-tag">px</span>;
</code></pre>
<p>From the code above, you can see that a gap of <code>20px</code> was assigned to the column.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/COLUMN-GAP-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>20px column-gap</em></p>
<h3 id="heading-row-gap-property">Row-gap property</h3>
<p>Just like <code>column-gap</code>, <code>row-gap</code> is a CSS property that assigns a space between two or more rows in a container. For example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">row-gap</span>: 50<span class="hljs-selector-tag">px</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ROW-GAP-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>row-gap: 50px;</em></p>
<p>Note that we can also assign a gap to both the columns and rows of a container by using the <code>gap</code> property. For this to work, we only assign one value to both the columns and the rows of the container, just like we did in the code above.</p>
<p>Here's an example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">gap</span>: 20<span class="hljs-selector-tag">px</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/GAP-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>gap: 20px</em></p>
<p>From the diagram above, we can see that a <code>gap</code> of <code>20px</code> was set to both the columns and rows of the container making them equally spaced.</p>
<h3 id="heading-justify-content-property">Justify-content property</h3>
<p>This is a grid property that you use in positioning items (columns and rows) horizontally in a container. It displays how the web browser positions the spaces around the items (columns and rows).</p>
<p>The justify-content property has six possible values:</p>
<ul>
<li><p><code>Start</code></p>
</li>
<li><p><code>end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
</ul>
<h4 id="heading-start">Start</h4>
<p>This positions the items at the left side of the browser and can be executed with the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">start</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/JUSTIFY-START-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>justify-content: start;</em></p>
<h4 id="heading-end">End</h4>
<p>This positions the items at the right side of the browser and can be executed with the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">end</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/JUSTIFY-END-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>justify-content: end;</em></p>
<h4 id="heading-center">Center</h4>
<p>This positions the items at the center of the browser and can be executed with the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">center</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/JUSTIFY-CENTER-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>justify-content: center;</em></p>
<h4 id="heading-space-around">Space-around</h4>
<p>This property distributes the items in the container evenly, where each item in the container has an equal amount of space from the next container.</p>
<p>This code can be executed like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">space-around</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/JUSTIFY-SPACE-AROUND-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>justify-content: space-around</em></p>
<h4 id="heading-space-between">Space-between</h4>
<p>Just like the <code>space-around</code> property, <code>space-between</code> distributes the items in the container evenly, where each item in the container has an equal amount of space from the next one in the container. It takes up the entire width of the container.</p>
<p>This code can be executed like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">space-between</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/JUSTIFY-SPACE-BETWEEN-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>justify-content: space-between</em></p>
<h4 id="heading-space-evenly">Space-evenly</h4>
<p>Just as the name states, this property distributes the items in the container evenly, where each item in the container has an equal amount of space from the next one in the container.</p>
<p>This code can be executed like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">justify-content</span>: <span class="hljs-selector-tag">space-evenly</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/JUSTIFY-SPACE-EVENLY-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>justify-content: space-evenly;</em></p>
<p>Note that all the <code>justify-content</code> properties position their items/elements horizontally. Try doing it yourself to understand it more.</p>
<h3 id="heading-align-content-property">Align-content property</h3>
<p><code>Align-content</code> is the opposite of <code>justify-content</code>. You use the <code>align-content</code> property in positioning items vertically in a container.</p>
<p>Just like <code>justify-content</code>, the <code>align-content</code> property has six possible values:</p>
<ul>
<li><p><code>Start</code></p>
</li>
<li><p><code>end</code></p>
</li>
<li><p><code>center</code></p>
</li>
<li><p><code>space-around</code></p>
</li>
<li><p><code>space-between</code></p>
</li>
<li><p><code>space-evenly</code></p>
</li>
</ul>
<h4 id="heading-start-1">Start</h4>
<p>This positions the items at the top of the browser and can be executed with the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span>: <span class="hljs-selector-tag">start</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ALIGN-CONTENT-START-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>align-content: start;</em></p>
<h4 id="heading-end-1">End</h4>
<p>This positions the items at the bottom of the browser and can be executed with the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span>: <span class="hljs-selector-tag">end</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ALIGN-CONTENT-END-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>align-content: end</em></p>
<h4 id="heading-center-1">Center</h4>
<p>This positions the items at the center of the browser and can be executed with the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span>: <span class="hljs-selector-tag">center</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ALIGN-CONTENT-CENTER-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>align-content: center;</em></p>
<h4 id="heading-space-around-1">Space-around</h4>
<p>This property distributes the items along the side of the container evenly, where each item in the container has an equal amount of space from the next one vertically.</p>
<p>This code can be executed like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span>: <span class="hljs-selector-tag">space-around</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ALIGN-CONTENT-SPACE-AROUND-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>align-content: space-around</em></p>
<h4 id="heading-space-between-1">Space-between</h4>
<p>Just like the <code>space-around</code> property, <code>Space-between</code> distributes the items in the container evenly, where each item in the container has an equal amount of space from the next one in the container, and takes up the entire width of the container in the vertical direction.</p>
<p>This code can be executed like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span>: <span class="hljs-selector-tag">space-between</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ALIGN-CONTENT-SPACE-BETWEEN-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>align-content: space-between</em></p>
<h4 id="heading-space-evenly-1">Space-evenly</h4>
<p>Just as the name states, this property distributes the items in the container evenly, where each item in the container has an equal amount of space from the next one vertically.</p>
<p>This code can be executed like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span>: <span class="hljs-selector-tag">space-evenly</span>;
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/ALIGN-CONTENT-SPACE-EVENLY-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>align-content: space-evenly</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In today's article, we studied what CSS Grid Layout is all about, why we should learn it, and the properties of CSS grid.</p>
<p>Thank you for reading.</p>
<p>Have fun coding!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ HTML Center Image – CSS Align Img Center Example ]]>
                </title>
                <description>
                    <![CDATA[ If you're making websites with HTML and CSS, you will be working with images a lot.  Developers often struggle with image alignment in CSS, especially when trying to figure out how to center an image. Centering anything in CSS is not really a straigh... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/html-center-image-css-align-img-center-example/</link>
                <guid isPermaLink="false">66adf1606f5e63db3fc43622</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ css flex ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Tue, 01 Feb 2022 21:16:57 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/02/arrows-2889040_1920.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you're making websites with HTML and CSS, you will be working with images a lot. </p>
<p>Developers often struggle with image alignment in CSS, especially when trying to figure out how to center an image.</p>
<p>Centering anything in CSS is not really a straightforward thing - especially for beginners. This is why people brag about being able to center a div. :)</p>
<p>Since the <code>img</code> element is an inline element, this makes it a little bit harder to center. But don't worry, you can convert the image to a block element and then center it.</p>
<p>In this article, I'm going to show you 4 different ways you can align an image to the center.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><a class="post-section-overview" href="#heading-how-to-center-an-image-with-the-text-align-property">How to Center an Image With the Text Align Property</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-an-image-with-flexbox">How to Center an Image with Flexbox</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-an-image-with-css-grid">How to Center an Image with CSS Grid</a></li>
<li><a class="post-section-overview" href="#heading-how-to-center-an-image-with-the-margin-property">How to Center an Image with the Margin Property</a></li>
</ul>
<h2 id="heading-how-to-center-an-image-with-the-text-align-property">How to Center an Image With the Text Align Property</h2>
<p>You can center an image with the <code>text-align</code> property. </p>
<p>One thing you should know is that the tag for bringing in images – <code>img</code> – is an inline element. Centering with the <code>text-align</code> property works for block-level elements only.</p>
<p>So how do you center an image with the text-align property? You wrap the image in a block-level element like a <code>div</code> and give the <code>div</code> a <code>text-align</code> of <code>center</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"fcc22.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"freeCodeCamp"</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-attribute">text-align</span>: center;
    }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/ss-1.png" alt="ss-1" width="600" height="400" loading="lazy"></p>
<h2 id="heading-how-to-center-an-image-with-flexbox">How to Center an Image with Flexbox</h2>
<p>The introduction of CSS Flexbox made it easier to center anything.</p>
<p>Flexbox works by putting what you want to center in a container and giving the container a <code>display</code> of <code>flex</code>. Then it sets <code>justify-content</code> to <code>center</code> as shown in the code snippet below:</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">div</span> {
      <span class="hljs-attribute">display</span>: flex;
      <span class="hljs-attribute">justify-content</span>: center;
    }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/ss-1.png" alt="ss-1" width="600" height="400" loading="lazy"></p>
<p><strong>P.S.:</strong> A <code>justify-content</code> property set to <code>center</code> centers an image horizontally. To center the image vertically too, you need to set <code>align-items</code>to <code>center</code>.</p>
<h2 id="heading-how-to-center-an-image-with-css-grid">How to Center an Image with CSS Grid</h2>
<p>CSS Grid works like Flexbox, with the added advantage that Grid is multidimensional, as opposed to Flexbox which is 2-dimensional.</p>
<p>To center an image with CSS Grid, wrap the image in a container div element and give it a display of <code>grid</code>. Then set the <code>place-items</code> property to center. </p>
<pre><code class="lang-css"> <span class="hljs-selector-tag">div</span> {
      <span class="hljs-attribute">display</span>: grid;
      <span class="hljs-attribute">place-items</span>: center;
    }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/ss-1.png" alt="ss-1" width="600" height="400" loading="lazy"></p>
<p><strong>P.S.:</strong><code>place-items</code> with a value of <code>center</code> centers anything horizontally and vertically.</p>
<h2 id="heading-how-to-center-an-image-with-the-margin-property">How to Center an Image with the Margin Property</h2>
<p>You can also center an image by setting a left and right margin of auto for it. But just like the <code>text-align</code> property, <code>margin</code> works for block-level elements only. </p>
<p>So, what you need to do is convert the image to a block-level element first by giving it a display of block.</p>
<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;
    }
</code></pre>
<p>Those 2 properties could be enough. But sometimes, you have to set a width for the image, so the left and right margin of auto would have spaces to take.</p>
<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-attribute">width</span>: <span class="hljs-number">40%</span>;
    }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/02/ss-2.png" alt="ss-2" width="600" height="400" loading="lazy"></p>
<p><strong>P.S.:</strong> You might not have to go as low as 40% for the width. The image was distorted at a 60+ percentage, that’s why I went as low as 40%.</p>
<p>I hope this article helps you choose which method works best for you in centering an image.</p>
<p>Thank you for reading.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Make an Animated Back to Top Button Using Only CSS ]]>
                </title>
                <description>
                    <![CDATA[ Having a "back to top" button on a website is important. It allows users to easily scroll back to the top of the page.  Most websites rely on JavaScript to toggle the visibility of the button based on the amount of scroll. In this post, I will show y... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-only-back-to-top-button/</link>
                <guid isPermaLink="false">66bb55d35a83db22bea9842b</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ HTML ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Temani Afif ]]>
                </dc:creator>
                <pubDate>Mon, 03 Jan 2022 21:18:12 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/12/header-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Having a "back to top" button on a website is important. It allows users to easily scroll back to the top of the page. </p>
<p>Most websites rely on JavaScript to toggle the visibility of the button based on the amount of scroll. In this post, I will show you how to create such an effect using only CSS.</p>
<p>We will explore two kinds of effects – a "sliding" and a "fading" effect.</p>
<h2 id="heading-how-to-make-a-sliding-back-to-top-button">How to Make a Sliding Back to Top Button</h2>
<p>Here is an overview of what we are building in this part:</p>
<details>
  <summary>Click to see the full code</summary>

  <code>html
  &lt;body&gt;
    &lt;div&gt;
      &lt;!-- your content goes here  --&gt;
    &lt;/div&gt;
    &lt;a href="#" class="top"&gt;Back to Top &amp;#8593;&lt;/a&gt;
  &lt;/body&gt;</code>
  <code>css
  body {
    display: grid;
    grid-template-columns: auto 0px; 
  }

  .top {
    --offset: 50px; 

    position: sticky;
    bottom: 20px;      
    margin-right: 10px; 
    place-self: end;
    margin-top: calc(100vh + var(--offset));

    /* visual styling */
    text-decoration: none;
    padding: 10px;
    font-family: sans-serif;
    color: #fff;
    background: #000;
    border-radius: 100px;
    white-space: nowrap;
  }

  p {
    font-size: 25px;
  }</code>
</details>

<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/9305df2ed45a40db3e654290147665ff" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>If you scroll, the "back to top" button will appear and will stick at the bottom of the page. Click on it and you will get back to the top! </p>
<p>You will find no JavaScript in there. We'll only use CSS to make the button appear when you scroll the page.</p>
<p>It's cool, right? Let's dissect the code to understand the magic behind it.</p>
<h3 id="heading-the-html-structure">The HTML Structure</h3>
<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>&gt;</span>
    <span class="hljs-comment">&lt;!-- your content goes here  --&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</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">"top"</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">body</span>&gt;</span>
</code></pre>
<p>Inside the <code>body</code> tag, we create a <code>div</code> where we put the content of the website. Right after that, we add our "back to top" button as a link. </p>
<p>For the sake of the article, I will keep the button as simple as possible but you can use whatever you want (an image, an icon, and so on). All you need is to keep the usage of <code>a</code> combined with <code>href="#"</code>.</p>
<p>That's it! We are done with the HTML structure.</p>
<h3 id="heading-the-css-code">The CSS Code</h3>
<p>We first start by styling our button. For this part, it's up to you to be creative and build your own button. I will use a basic button (<code>&lt;a class="top" href="#"&gt;Back to Top ↑&lt;/a&gt;</code>) styled like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.top</span> {
  <span class="hljs-attribute">text-decoration</span>: none;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
  <span class="hljs-attribute">font-family</span>: sans-serif;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#fff</span>;
  <span class="hljs-attribute">background</span>: <span class="hljs-number">#000</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">100px</span>;
}
</code></pre>
<p>Which will get us the following result:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/back-to-top.png" alt="back to top button" width="600" height="400" loading="lazy"></p>
<p>Let's move to the main CSS. The effect we are aiming for uses two CSS techniques:</p>
<ol>
<li>CSS Grid to create the main structure</li>
<li><code>position: sticky</code> to be able to keep the button at the bottom of the screen</li>
</ol>
<p>Our structure will be a grid of two columns – one for the content and another one for the "back to top" button. For this, we add the following code:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: auto auto;
}
</code></pre>
<p>This gives us the following result:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/f356b9aa5d03912dec73d9d4f2305eb7" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Yes, it looks "ugly" but don't worry. This is due to the default stretch alignment of CSS Grid. We have to disable it and place our button at the bottom using <code>place-self: end</code>.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/1e33f3acf4c05a730eb259b63e9bee82" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Now let's introduce <code>position: sticky</code> by adding this code:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.top</span> {
  <span class="hljs-attribute">position</span>: sticky;
  <span class="hljs-attribute">bottom</span>: <span class="hljs-number">20px</span>; 
}
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/97fc75f4e30d29baf2100a6684dc2e32" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Our button is fixed at the bottom right of our screen thanks to our "sticky" behavior. Now we need to control that behavior to make the button initially hidden. For this, we will use <code>margin-top</code> with a value equal to the screen height (<code>100vh</code> ).</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/d60f76ae3dc8a77a8a3c99a7840b4b87" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>See that? Our button appears only when we scroll the screen and then remains fixed. We are getting closer!</p>
<p>Let's do better by adding an offset. Our <code>margin-top</code> will become:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.top</span> {
  <span class="hljs-attribute">--offset</span>: <span class="hljs-number">100px</span>; 

  <span class="hljs-attribute">margin-top</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">100vh</span> + var(--offset));
}
</code></pre>
<p>The above means: "After 100px of scrolling, show the button". To the screen height, we add an offset (that we define using a CSS variable) to control when the button should appear. </p>
<p>The final touch is to make the column width of the button equal to 0 by changing <code>grid-template-columns: auto auto</code> into <code>grid-template-columns: auto 0px</code>.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/a44aaf99ec97bc19418095306ae9cf19" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Oops, the button is messed up! Since we reduced the space of the button to 0, the latter will try to fit that space by adding line breaks. To fix this, we simply add <code>white-space: nowrap</code> to disable the line breaks.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/6de5b9a160a83b279a33a651f92ff2d8" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>We made our first CSS-only "back to top" button with a sliding effect.</p>
<ul>
<li>You can adjust the offset to control when the button should appear</li>
<li>Using <code>bottom</code> and <code>margin-right</code> you can control the distance from the bottom right corner of the screen.</li>
</ul>
<p>Let's not forget that you can easily style the button as you want. Here is another idea using the same code structure:</p>
<details>
  <summary>Click to see the full code</summary>

  <code>html
  &lt;body&gt;
    &lt;div&gt;
      &lt;!-- your content goes here  --&gt;
    &lt;/div&gt;
    &lt;a href="#" class="top"&gt;Back to Top &amp;#8593;&lt;/a&gt;
  &lt;/body&gt;</code>
  <code>css
  body {
    display: grid;
    grid-template-columns: auto 0px; 
  }

  .top {
    --offset: 50px; 

    position: sticky;
    bottom: 20px;      
    margin-right: 10px; 
    place-self: end;
    margin-top: calc(100vh + var(--offset));

    /* visual styling */
    width: 45px;
    aspect-ratio: 1;
    background: #ff8b24;
    border-radius: 10px;
  }

  .top:before {
    content: "";
    position: absolute;
    inset: 30%;
    transform: translateY(20%) rotate(-45deg);
    border-top: 5px solid #fff;
    border-right: 5px solid #fff;
  }

  p {
    font-size: 25px;
  }</code>
</details>

<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/5931fe72a76540644679e8453a8c3b41" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-how-to-make-a-fading-back-to-top-button">How to Make a Fading Back to Top Button</h2>
<p>Let's tackle the second type of button where we will have a "fading" effect. Here's an overview of what we will create here:</p>
<details>
  <summary>Click to see the full code</summary>

  <code>html
  &lt;body&gt;
    &lt;div&gt;
      &lt;!-- your content goes here  --&gt;
    &lt;/div&gt;
    &lt;div class="container-top"&gt;
      &lt;a href="#" class="top"&gt;&lt;/a&gt;
    &lt;/div&gt;
  &lt;/body&gt;</code>
  <code>css
  body {
    display: grid;
    grid-template-columns: auto 0px; 
  }

  .container-top {
    --offset: 100px;
    --fade: 120px;

    display: flex;
    align-items: flex-end;
    width: 60px;
    justify-self: end;
    justify-content: flex-end;
    -webkit-mask: linear-gradient(#0000 calc(100vh + var(--offset)), #000 calc(100vh + var(--offset) + var(--fade)));
  }

  .top {
    position: sticky;
    bottom: 20px;      
    margin-right: 10px; 

    /* visual styling */
    width: 100%;
    aspect-ratio: 1;
    background: #ff8b24;
    border-radius: 10px;
  }

  .top:before {
    content: "";
    position: absolute;
    inset: 30%;
    transform: translateY(20%) rotate(-45deg);
    border-top: 5px solid #fff;
    border-right: 5px solid #fff;
  }

  p {
    font-size: 25px;
  }</code>
</details>

<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/ee83bb0f509273da920f7a8b48deea70" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Like the previous effect, you will find zero JavaScript code. That fading effect is handled with only CSS.</p>
<p>Let's dig into this one!</p>
<h3 id="heading-the-html-structure-1">The HTML structure</h3>
<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>&gt;</span>
    <span class="hljs-comment">&lt;!-- your content goes here  --&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">"container-top"</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">"top"</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">body</span>&gt;</span>
</code></pre>
<p>It's very similar to the previous example. We've simply added an extra wrapper around our "back to top" button.</p>
<h3 id="heading-the-css-code-1">The CSS code</h3>
<p>I will skip the part where we style the button since it's the same as the previous effect.</p>
<p>This effect also relies on CSS grid and <code>position: sticky</code>. We'll also use a third technique which is the <code>mask</code> property (the one that will simulate the fading effect).</p>
<p>Let's start with the main setting:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">grid-template-columns</span>: auto auto; 
}

<span class="hljs-selector-class">.container-top</span> {
  <span class="hljs-attribute">display</span>: flex;
  <span class="hljs-attribute">align-items</span>: flex-end;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">60px</span>;
}

<span class="hljs-selector-class">.top</span> {
  <span class="hljs-attribute">position</span>: sticky;
  <span class="hljs-attribute">bottom</span>: <span class="hljs-number">20px</span>;      
  <span class="hljs-attribute">margin-right</span>: <span class="hljs-number">10px</span>; 
}
</code></pre>
<p>We define our two-column layout where the <code>container-top</code> is the second one. We make the latter a flex container and we place the button at the very bottom using <code>align-items: flex-end</code>. Finally, we use <code>position: sticky</code> to have the button fixed at the bottom right of the screen.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/89a50537ca3c7b6333af56ba55d5b7d2" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Now let's introduce the <code>mask</code> property to create the fading effect. To understand this trick, I will first use a background to illustrate how it works.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/3ba95f0e83ed5a21f0dbc9cd8e3751d1" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>In the above, I applied the following gradient to <code>container-top</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container-top</span> {
  <span class="hljs-attribute">background</span>: <span class="hljs-built_in">linear-gradient</span>(green <span class="hljs-number">100vh</span>, red <span class="hljs-number">0</span>);
}
</code></pre>
<p>If you scroll, you will notice that the button will move from the green area to the red one. The green area is equal to the screen height.</p>
<p>Imagine that the green area is the "invisible" part of the <code>container-top</code> and the red one is the "visible" part. This is what <code>mask</code> will be doing if we consider the same gradient.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/612cd0ac11098d0f5030a833e1707d1d" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>In this last demo, we changed <code>background</code> with <code>mask</code> and we used a transparent/opaque combination of colors instead of the green/red one. The button now appears only on scroll!</p>
<p>To get the fading effect, we need to increase the distance between both colors. Let's introduce a CSS variable and update the mask like below:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container-top</span> {
  <span class="hljs-attribute">--fade</span>: <span class="hljs-number">120px</span>;
  <span class="hljs-attribute">mask</span>: <span class="hljs-built_in">linear-gradient</span>(#<span class="hljs-number">0000</span> <span class="hljs-number">100vh</span>, #<span class="hljs-number">000</span> calc(<span class="hljs-number">100vh</span> + var(--fade)));
}
</code></pre>
<p>The transparent color ends at <code>100vh</code>, and the opaque one start at <code>100vh + 120px</code>. We have a fading of <code>120px</code> between transparent and opaque which gives us the following result:</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/4b34d1f80f60a281bec7a36cfce16be9" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>We are almost there! Our button is fading like expected. We are simply missing the offset variable to control when the fading effect should happen.</p>
<p>For this, we do the same as the previous effect by introducing the <code>offset</code> variable:</p>
<p>The final touch is to make the column width of <code>container-top</code> equal to 0 using <code>grid-template-columns: auto 0px</code></p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container-top</span> {
  <span class="hljs-attribute">--offset</span>: <span class="hljs-number">100px</span>;
  <span class="hljs-attribute">--fade</span>: <span class="hljs-number">120px</span>;

  <span class="hljs-attribute">mask</span>: <span class="hljs-built_in">linear-gradient</span>(#<span class="hljs-number">0000</span> calc(<span class="hljs-number">100vh</span> + var(--offset)), <span class="hljs-number">#000</span> <span class="hljs-built_in">calc</span>(<span class="hljs-number">100vh</span> + var(--offset) + <span class="hljs-built_in">var</span>(--fade)));
}
</code></pre>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/t_afif/embed/86f79c96520a0c864324db70a6b76c76" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>Our second  "back to top" button is done! Like the previous one, you can easily control the offset, the fading effect, and the position by adjusting the CSS variables, the <code>bottom</code> property, and the <code>margin-right</code> property.</p>
<p>Thank you for reading!</p>
<p>For more CSS tips, follow me on <a target="_blank" href="https://twitter.com/ChallengesCss">Twitter</a>.</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[ The CSS Display Property – Display None, Display Table, Inline Block and More ]]>
                </title>
                <description>
                    <![CDATA[ In CSS, the display property determines how an element looks. It is also a crucial part of the presentation of your HTML code as it has a significant impact on layouts. In fact, to use the modern Flexbox and Grid models, you need to use the display p... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-css-display-property-display-none-display-table-inline-block-and-more/</link>
                <guid isPermaLink="false">66adf232db5636c0b30cba95</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ css flex ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kolade Chris ]]>
                </dc:creator>
                <pubDate>Thu, 19 Aug 2021 20:47:14 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/css-display-property.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In CSS, the display property determines how an element looks. It is also a crucial part of the presentation of your HTML code as it has a significant impact on layouts.</p>
<p>In fact, to use the modern Flexbox and Grid models, you need to use the display property before you get access to their various properties and values. This is one reason why the display property is so important in CSS.</p>
<p>Let's dive in and learn how to use the <code>display</code> property and all its different values.</p>
<h2 id="heading-basic-display-property-syntax">Basic <code>display</code> Property Syntax</h2>
<pre><code class="lang-html">element {
        display: value;
     }
</code></pre>
<h2 id="heading-display-property-values-in-css">Display Property Values in CSS</h2>
<p>There are inline and block-level elements in CSS. The difference between the two is that inline elements don't take up an entire space – that is, they don't start on a new line – but block elements do.</p>
<p>The display property takes many different values such as <code>inline</code>, <code>inline-block</code>, <code>block</code>, <code>table</code>, and more, which all influence the layout and presentation of an element on the web page. Also, to implement the flex and grid layouts, you need to use the display property.</p>
<p>You can use this display property to change an <code>inline</code> element to <code>block</code>, <code>block</code> element to <code>inline</code>, <code>block</code> and <code>inline</code> elements to <code>inline-block</code>, and many more.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/display-property-values.png" alt="display-property-values" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-inline"><code>display: inline</code></h3>
<p>An element with a display property set to <code>inline</code> will not start on a new line and it will take up the remaining/available screen width. It just takes up the space such an element would normally take.</p>
<p>Because of this, you can't set the <code>width</code> and <code>height</code> of an element that has a display of <code>inline</code>, becuase it does not take up the whole screen width.</p>
<p>Some elements are inline by default, like <code>&lt;span&gt;</code>, <code>&lt;a&gt;</code>, <code>&lt;i&gt;</code>, and <code>&lt;img&gt;</code>.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      Lorem ipsum dolor sit amet consectetur adipisicing elit.
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>This is an inline lement<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Modi eaque debitis eos quod labore
      maiores delectus asperiores voluptatem voluptas soluta!
<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">body</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">100vh</span>;
        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
      }
<span class="hljs-selector-tag">div</span> {
        <span class="hljs-attribute">max-width</span>: <span class="hljs-number">600px</span>;
      }
<span class="hljs-selector-tag">span</span> {
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
      }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/inline-display.png" alt="inline-display" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-block"><code>display: block</code></h3>
<p>An element that has the display property set to <code>block</code> starts on a new line and takes up the available screen width.</p>
<p>You can specify the <code>width</code> and <code>height</code> properties for such elements. Examples of elements that are at block-level by default are <code>&lt;div&gt;</code>, <code>&lt;section&gt;</code>, <code>&lt;p&gt;</code>, and lots more.</p>
<p>You can set the <code>span</code> from the previous HTML code to <code>block</code> display and it will behave like a block-level element.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">span</span> {
        <span class="hljs-attribute">display</span>: block;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
      }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/block-display.png" alt="block-display" width="600" height="400" loading="lazy"></p>
<p>You can see that the <code>&lt;span&gt;</code> takes up the full width. That's because it has a display property set to block.</p>
<h3 id="heading-display-inline-block"><code>display: inline-block</code></h3>
<p>Apart from block and inline display, there's also inline-block.</p>
<p>An element you assign a display of <code>inline-block</code> is inline by presentation. But it has the added advantage of you being able to apply <code>width</code> and <code>height</code> to it, which you can't do when the element is assigned a dispaly of <code>inline</code>.</p>
<p>So, you can look at the <code>inline-block</code> display as an inline element and block element in one package.</p>
<pre><code class="lang-css"> <span class="hljs-selector-tag">span</span> {
        <span class="hljs-attribute">display</span>: inline-block;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
      }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/inline-block-display.png" alt="inline-block-display" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-none"><code>display: none</code></h3>
<p>When you set the display property of an element to <code>none</code>, the element is completely taken off the page and it doesn’t have an effect on the layout.</p>
<p>This also means that devices like screen readers, which make websites accessible to blind people, wont't have access to the element.</p>
<p>Do not confuse <code>display: none</code> with <code>visibility: hidden</code>. The latter also hides the element, but leaves the space it would normally take open or empty.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">span</span> {
        <span class="hljs-attribute">display</span>: none;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
      }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/display-none.png" alt="display-none" width="600" height="400" loading="lazy"></p>
<p>Visibility hidden leaves the space occupied by the span element open, as you can see below:</p>
<pre><code class="lang-css"> <span class="hljs-selector-tag">span</span> {
        <span class="hljs-attribute">visibility</span>: hidden;
        <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
      }
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/visibility-hidden.png" alt="visibility-hidden" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-table"><code>display: table</code></h3>
<p>You'll rarely use a display value of <code>table</code> these days, but it's still important to know. It was more useful in the past because you would use it for layouts before the advent of floats, Flex, and Grid.</p>
<p>Setting display to <code>table</code> makes the element behave like a table. So you can make a replica of an HTML table without using the table element and corresponding elements such as <code>tr</code> and <code>td</code>.</p>
<p>For example, in HTML, you can make a table with the <code>&lt;table&gt;</code> element and also a <code>&lt;div&gt;</code>, or any container of your choice.</p>
<p>You make a table with the HTML <code>&lt;table&gt;</code> element like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">table</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Fruits<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Lemurs<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Pets<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Cashew<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Hua hua<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Dog<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Apple<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Diadem Sifaka<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Cat<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Mango<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Rig-tailed<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>Chicken<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</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">100vh</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
}

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

<span class="hljs-selector-tag">span</span> {
    <span class="hljs-attribute">display</span>: inline-block;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
}

<span class="hljs-selector-tag">tr</span>,
<span class="hljs-selector-tag">td</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>The result of the HTML and CSS code snippets above looks like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/table-with-table-element.png" alt="table-with-table-element" width="600" height="400" loading="lazy"></p>
<p>But you can make the same table with the <code>&lt;div&gt;</code> element by setting the respective displays to <code>table</code>, <code>table-row</code>, and <code>table-cell</code>. You will get the same result as you can see 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">"table"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"row"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cell"</span>&gt;</span>Fruits<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">"cell"</span>&gt;</span>Lemurs<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">"cell"</span>&gt;</span>Pets<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">"row"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cell"</span>&gt;</span>Cashew<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">"cell"</span>&gt;</span>Hua hua<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">"cell"</span>&gt;</span>Dog<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">"row"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cell"</span>&gt;</span>Apple<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">"cell"</span>&gt;</span>Diadem Sifaka<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">"cell"</span>&gt;</span>Cat<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">"row"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"cell"</span>&gt;</span>Mango<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">"cell"</span>&gt;</span>Ring-tailed<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">"cell"</span>&gt;</span>Chicken<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>
</code></pre>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</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">100vh</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
}

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

<span class="hljs-selector-tag">span</span> {
    <span class="hljs-attribute">display</span>: inline-block;
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
    <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
}

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

<span class="hljs-selector-class">.row</span> {
   <span class="hljs-attribute">display</span>: table-row;
}

<span class="hljs-selector-class">.cell</span> {
   <span class="hljs-attribute">display</span>: table-cell;
}

<span class="hljs-selector-class">.row</span>,
<span class="hljs-selector-class">.cell</span> {
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>;
}
</code></pre>
<p>You still get your table:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/table-with-div.png" alt="table-with-div" width="600" height="400" loading="lazy"></p>
<h2 id="heading-other-values-of-the-display-property">Other values of the Display Property</h2>
<p>Apart from <code>inline</code>, <code>block</code>, <code>none</code>, and <code>table</code>, which are really important because they significantly influence how web pages look, there are other values of the <code>display</code> property worthy of your attention.</p>
<p>Some of them you'll use all the time without really realizing that they are also part of the display property. And others you won't use often at all.</p>
<p>Let's look at some of them now.</p>
<h3 id="heading-display-flex"><code>display: flex</code></h3>
<p>A display of <code>flex</code> gives you access to the Flex layout system, which simplifies how we design and layout our web pages.</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">"child"</span>&gt;</span>
        Lorem ipsum dolor sit amet consectetur adipisicing elit.
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>This is an inline element<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Modi eaque debitis eos quod
        labore maiores delectus asperiores voluptatem voluptas soluta!
      <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">"child"</span>&gt;</span>
        Lorem ipsum dolor sit amet consectetur adipisicing elit.
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>This is an inline element<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Modi eaque debitis eos quod
        labore maiores delectus asperiores voluptatem voluptas soluta!
      <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">100vh</span>;
        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
}

<span class="hljs-selector-tag">span</span> {
       <span class="hljs-attribute">visibility</span>: hidden;
       <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
       <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
       <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
}

<span class="hljs-selector-class">.child</span> {
       <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid crimson;
       <span class="hljs-attribute">margin</span>: <span class="hljs-number">4px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/display-flex.png" alt="display-flex" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-grid"><code>display: grid</code></h3>
<p>A display set to <code>grid</code> allows you to build layouts with the grid system, which is like an advanced form of flex.</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">"child"</span>&gt;</span>
        Lorem ipsum dolor sit amet consectetur adipisicing elit.
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>This is an inline element<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Modi eaque debitis eos quod
        labore maiores delectus asperiores voluptatem voluptas soluta!
      <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">"child"</span>&gt;</span>
        Lorem ipsum dolor sit amet consectetur adipisicing elit.
        <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>This is an inline element<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Modi eaque debitis eos quod
        labore maiores delectus asperiores voluptatem voluptas soluta!
      <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">place-items</span>: center;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
        <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
      }

<span class="hljs-selector-tag">span</span> {
       <span class="hljs-attribute">visibility</span>: hidden;
       <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#006100</span>;
       <span class="hljs-attribute">width</span>: <span class="hljs-number">140px</span>;
        <span class="hljs-attribute">height</span>: <span class="hljs-number">140px</span>;
}

<span class="hljs-selector-class">.child</span> {
       <span class="hljs-attribute">border</span>: <span class="hljs-number">2px</span> solid crimson;
       <span class="hljs-attribute">margin</span>: <span class="hljs-number">4px</span>;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/display-grid.png" alt="display-grid" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-inherit"><code>display: inherit</code></h3>
<p>This makes the element inherit the display property of its parent. So, if you have a <code>&lt;span&gt;</code> tag inside a div and you give the span tag a display of <code>inherit</code>, it turns it from inline to block element.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      Lorem ipsum dolor sit amet consectetur
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Inline element<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> adipisicing elit. Cumque cupiditate harum
      consectetur a exercitationem laboriosam nobis eos pariatur expedita iure.
<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">body</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">100vh</span>;
     <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
}

<span class="hljs-selector-tag">span</span> {
     <span class="hljs-attribute">display</span>: inherit;
     <span class="hljs-attribute">background-color</span>: crimson;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/display-inherit.png" alt="display-inherit" width="600" height="400" loading="lazy"></p>
<h3 id="heading-display-initial"><code>display: initial</code></h3>
<p>This sets the display property of an element to its default value. So, if you set the display property of a span to initial, it remains inline, and if you set the same value for a div, it remains block.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      Lorem ipsum dolor sit amet consectetur
      <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>Inline element<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> adipisicing elit. Cumque cupiditate harum
      consectetur a exercitationem laboriosam nobis eos pariatur expedita iure.
<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">body</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">100vh</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">2rem</span>;
}

<span class="hljs-selector-tag">span</span> {
    <span class="hljs-attribute">display</span>: initial;
    <span class="hljs-attribute">background-color</span>: crimson;
}
</code></pre>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/display-initial.png" alt="display-initial" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Having a good grasp of the display property will help your page layouts look great. It also gives you a lot more control over the way you present your elements while working with CSS.</p>
<p>You can continue to come back to this article for reference too as the display property is always confusing at first until you use it enough to understand it fully.</p>
<p>I hope this article has given you the background knowledge you need in order to put the display property to good use.</p>
<p>Thank you for reading, and keep coding.</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[ 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>
        
            <item>
                <title>
                    <![CDATA[ Complete CSS Grid Tutorial with Cheat Sheet 🎖️ ]]>
                </title>
                <description>
                    <![CDATA[ Today we're going to learn CSS Grid properties so that you can make your own responsive websites. I'll explain how each of Grid's properties work along with a CheatSheet that covers everything you can do with Grid. Let's go. 🎖️ Table of Contents: C... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-grid-tutorial-with-cheatsheet/</link>
                <guid isPermaLink="false">66b2095227569435a9255afe</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Joy Shaheb ]]>
                </dc:creator>
                <pubDate>Tue, 08 Jun 2021 16:02:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/06/FCC.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Today we're going to learn <strong>CSS Grid</strong> properties so that you can make your own responsive websites. I'll explain how each of Grid's properties work along with a CheatSheet that covers everything you can do with Grid. Let's go. 🎖️</p>
<h1 id="heading-table-of-contents">Table of Contents:</h1>
<ul>
<li><a class="post-section-overview" href="#heading-css-grid-architecture">CSS Grid Architecture</a></li>
<li><a class="post-section-overview" href="#heading-css-grid-chart">CSS Grid Chart</a></li>
<li><a class="post-section-overview" href="#heading-css-grid-parent-properties">Grid Parent Properties</a><ul>
<li><a class="post-section-overview" href="#heading-the-grid-template-columns-property">grid-template-columns</a></li>
<li><a class="post-section-overview" href="#heading-the-grid-template-rows-property">grid-template-rows</a></li>
<li><a class="post-section-overview" href="#heading-the-grid-template-areas-property-1">grid-template-areas</a></li>
<li><a class="post-section-overview" href="#heading-the-column-gap-property">How to create column and row gaps in Grid</a></li>
<li><a class="post-section-overview" href="#heading-the-justify-items-property">How to justify items and align items with Grid</a></li>
<li><a class="post-section-overview" href="#heading-the-justify-content-property">How to justify content and align-content with Grid</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-css-grid-child-properties">Child Properties in CSS Grid</a><ul>
<li><a class="post-section-overview" href="#heading-the-grid-column-startend-properties">grid-column : start/end</a></li>
<li><a class="post-section-overview" href="#heading-the-grid-row-startend-properties">grid-row : start/end</a></li>
<li><a class="post-section-overview" href="#heading-the-grid-area-property">grid-area</a></li>
<li><a class="post-section-overview" href="#heading-the-justify-self-property">justify-self || align-self</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-shorthand-for-css-grid-properties">Shorthand for Grid</a></li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<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/VXW1r09Y6Tw" 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>
<h1 id="heading-first-what-is-css-grid">First, What is CSS Grid?</h1>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6e3wc9k9qxw07o54e38x.png" alt="Alt Text" width="1340" height="591" loading="lazy"></p>
<p>Grid is a blueprint for making websites.</p>
<p>The Grid model allows you to layout the content of your website. Not only that, it helps you create the structures you need for building responsive websites for multiple devices. This means your site will look good on desktop, mobile, and tablet.</p>
<p>Here's a simple demo which I created using Grid as the main blueprint.</p>
<h3 id="heading-desktop-view">Desktop View</h3>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zuz7de20oxw7t8kmid4s.png" alt="Alt Text" width="1500" height="844" loading="lazy"></p>
<h3 id="heading-mobile-view">Mobile View</h3>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wqtabiihl0kexxdbvht.png" alt="Alt Text" width="695" height="983" loading="lazy"></p>
<h1 id="heading-css-grid-architecture">CSS Grid Architecture</h1>
<p>So how does Grid architecture work? The Grid items [Contents] are distributed along the main axis and cross axis. Using various Grid properties, you can manipulate the items to create your website layouts.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h9qs07pm0a8s20scr6wr.png" alt="Grid Architecture" width="1440" height="1024" loading="lazy">
<em>grid architecture</em></p>
<p>By the way, you can join multiple rows and columns, just like in Excel software, which gives you more flexibility and options than Flexbox.</p>
<p>By the way, here's a CheatSheet I made for <a target="_blank" href="https://www.freecodecamp.org/news/css-flexbox-tutorial-with-cheatsheet/">Flexbox</a> if you want to learn more about that.</p>
<h1 id="heading-css-grid-chart">CSS Grid Chart</h1>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s3oecuzn41ee3gj4o1ny.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<p>This chart contains every possible property you can use when using grid. Grid properties are divided into:</p>
<ul>
<li>Parent properties</li>
<li>Child Properties</li>
</ul>
<p><strong>Note:</strong> The red colored text denotes the shorthand properties:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n93mkan7du7wz3zyibtw.png" alt="Alt Text" width="1280" height="973" loading="lazy"></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5g3msf9v3yw9qjpzkvj7.png" alt="Alt Text" width="1280" height="687" loading="lazy"></p>
<p>By the end of this tutorial, you'll have a clear understanding of how to use all of those properties.</p>
<h1 id="heading-how-to-set-up-the-project">How to Set Up the Project</h1>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c9bfd2puec1wjuk063k.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<p>For this project, you need to know little bit of HTML, CSS, and how to work with VS code. Follow along with me as we complete the following tasks:</p>
<ol>
<li>Create a folder named "Project-1" and Open VS Code</li>
<li>Create index.html and style.css files</li>
<li>Install Live Server and run it.</li>
</ol>
<p>Or, you can just open <a target="_blank" href="https://codepen.io">Codepen</a> and start coding.</p>
<p>At the end of this tutorial, you will be able to make accurate and beautiful website layouts.</p>
<p>And...we're all set! Let's start coding. 😊</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfjntw9islnyhv6mkigq.png" alt="Alt Text" width="1006" height="421" loading="lazy"></p>
<h2 id="heading-html">HTML</h2>
<p>Create three boxes inside the body tag, like this 👇</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> A <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">"box-2"</span>&gt;</span> B <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">"box-3"</span>&gt;</span> C <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>
<h2 id="heading-css">CSS</h2>
<h3 id="heading-step-1">Step 1</h3>
<p>Let's clear out our default browser styles. Follow me 👇</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>
<h3 id="heading-step-2">Step 2</h3>
<p>Inside the body selector, do these adjustments:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span> {
  <span class="hljs-attribute">font-family</span>: sans-serif;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">40px</span>;
  <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
  <span class="hljs-attribute">min-height</span>: <span class="hljs-number">100vh</span>;
}
</code></pre>
<h3 id="heading-step-3">Step 3</h3>
<p>Now, let's style our boxes by selecting all of them together -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-attr">[class^=<span class="hljs-string">"box-"</span>]</span> {
  <span class="hljs-attribute">background-color</span>: skyblue;

<span class="hljs-comment">/* To place the letter at the center */</span>
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">place-items</span>: center;
}
</code></pre>
<p><strong>Note:</strong> Don't worry, we'll discuss those grid properties in detail later.</p>
<h3 id="heading-step-4">Step 4</h3>
<p>Now, place some gaps between our boxes like this 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
}
</code></pre>
<h2 id="heading-but-wait">But Wait....</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cq8exwor5aiciu2j6jwu.png" alt="Alt Text" width="1488" height="600" loading="lazy"></p>
<p>Before starting, you need to understand the relationship between parent and child classes.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wzq3w0bys78fveqb9z0z.png" alt="Alt Text" width="1440" height="755" loading="lazy"></p>
<p>For the Grid parent property, we will write inside the <code>.container</code> class. For the Grid child property, we will write in the <code>.box-*</code> classes.</p>
<h1 id="heading-css-grid-parent-properties">CSS Grid Parent Properties</h1>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwnmeomlyekzuov7tcml.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<p>First, let's learn about CSS Grid's parent properties!</p>
<h2 id="heading-the-grid-template-columns-property">The grid-template-columns property</h2>
<p>You use this property to define the <strong>number and width</strong> of columns. You can either individually set the width of each column, or set a uniform width for all columns using the <code>repeat()</code> function.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pu3jedhac2u0onuan6go.png" alt="Alt Text" width="1440" height="568" loading="lazy"></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mov0pc7djie6gbj7m25g.png" alt="Alt Text" width="1440" height="656" loading="lazy">
<em>grid-template-columns</em></p>
<p>To recreate these results, write the following CSS lines -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;

<span class="hljs-comment">/*  Change the values     👇 to experiment */</span>
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">200px</span> auto <span class="hljs-number">100px</span>;
}
</code></pre>
<p><strong>Note:</strong></p>
<ul>
<li>The pixel values will be an exact measurement. The "auto" keyword will cover the available space.</li>
<li>If you use fr (fraction unit) as a unit of measurement, all the boxes will be equal in size.</li>
</ul>
<h2 id="heading-the-grid-template-rows-property">The grid-template-rows property</h2>
<p>You use this property to define the <strong>number and height</strong> of rows. You can either individually set the height of each row, or set a uniform height for all rows using the <code>repeat()</code> function.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r78wfrp3rr4mmn3507ym.png" alt="Alt Text" width="1440" height="1175" loading="lazy"></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/elpj9jw29ydlwao1yb3q.png" alt="Alt Text" width="1440" height="1076" loading="lazy">
<em>grid-template-rows</em></p>
<p>To test these results, write the following CSS code -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

<span class="hljs-comment">/* Change the values  👇 to experiment */</span>
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">200px</span> auto <span class="hljs-number">100px</span>;
}
</code></pre>
<h2 id="heading-the-grid-template-areas-property">The grid-template-areas property</h2>
<p>You use this property to specify the amount of space a grid cell should carry in terms of columns and rows across the parent container. Life's much easier with this property as it allows us to see visually what we're doing.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9nw9e0e1wk96wg3uq99f.png" alt="Alt Text" width="1440" height="1024" loading="lazy">
<em>Standard 12X12 layout</em></p>
<p>Call it the blueprint(template) of our layout👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nffhbw0eho476i535eyu.png" alt="Alt Text" width="1440" height="615" loading="lazy">
<em>The blueprint</em></p>
<p>To experiment with this, you need to understand both the parent and child properties:</p>
<ul>
<li><strong>grid-template-areas:</strong> The parent property that will create the blueprint</li>
<li><strong>grid-area:</strong> the child property that will follow the blueprint.</li>
</ul>
<h3 id="heading-first-create-the-blueprint">First, create the blueprint</h3>
<p>Like this 👇 inside the parent .container 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">gap</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

  <span class="hljs-attribute">grid-template-areas</span>: 
    <span class="hljs-string">"A A A A   A A A A   A A A A"</span>
    <span class="hljs-string">"B B B B   B B B B   B B C C"</span>
    <span class="hljs-string">"B B B B   B B B B   B B C C"</span>;
}
</code></pre>
<h3 id="heading-implement-the-blueprint">Implement the blueprint</h3>
<p>Target all our child <code>.box-*</code> classes and set the values like this -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
  <span class="hljs-attribute">grid-area</span>: A;
}
<span class="hljs-selector-class">.box-2</span>{
  <span class="hljs-attribute">grid-area</span>: B;
}
<span class="hljs-selector-class">.box-3</span>{
  <span class="hljs-attribute">grid-area</span>: C;
}
</code></pre>
<p><strong>Note:</strong> I'll discuss the grid-area property again in the grid child property section.</p>
<h2 id="heading-the-column-gap-property">The column-gap property</h2>
<p>You use this property to place a gap between <strong>Columns</strong> inside the grid 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fa59gtskckoh7ms1uk1h.png" alt="Alt Text" width="1309" height="642" loading="lazy">
<em>column-gap</em></p>
<p>To test this, write the following in CSS 👇</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>;

  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">100px</span> <span class="hljs-number">100px</span> <span class="hljs-number">100px</span>;
//Change values👇 to experiment
  <span class="hljs-attribute">column-gap</span>:  <span class="hljs-number">50px</span>;
}
</code></pre>
<p><strong>Note:</strong> column-gap works with grid-template-columns.</p>
<h2 id="heading-the-row-gap-property">The row-gap property</h2>
<p>You use this property to place a gap between <strong>Rows</strong> inside the grid 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aw6l38lydlag1dtzw9j8.png" alt="Alt Text" width="981" height="1218" loading="lazy">
<em>row gap</em></p>
<p>Let's test this 👇</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>;

  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">100px</span> <span class="hljs-number">100px</span> <span class="hljs-number">100px</span>;
// Change   👇  values to experiment
  <span class="hljs-attribute">row-gap</span>:  <span class="hljs-number">50px</span>;
}
</code></pre>
<p><strong>Note:</strong> row-gap works with grid-template-rows.</p>
<h2 id="heading-the-justify-items-property">The justify-items property</h2>
<p>You use this property to position grid-items (children) inside grid containers along the <strong>X-Axis [Main Axis]</strong>. The <strong>4</strong> values are 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oka32lvb2i0lrhcb8p4e.png" alt="Alt Text" width="1213" height="1026" loading="lazy"></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4r2jv92rgp3514fsp4ft.png" alt="Alt Text" width="1256" height="1046" loading="lazy">
<em>justify-items</em></p>
<p>If you want to test this, then add 1 more box inside the HTML -&gt;</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-comment">&lt;!--Other boxes - A, B, C are here--&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"box-4"</span>&gt;</span> D <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>
<p>and in the CSS -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

// each box is 200px by 200px
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;

//  Change values 👇  to experiment
  <span class="hljs-attribute">justify-items </span>: end;
}
</code></pre>
<h2 id="heading-the-align-items-property">The align-items property</h2>
<p>You use this property to position grid-items (children) inside the grid container along the <strong>Y-Axis [Cross Axis]</strong>. The <strong>4</strong> values are 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abl60fsmjuys1kadh1ig.png" alt="Alt Text" width="1752" height="1115" loading="lazy">
<em>align-items</em></p>
<p>Don't change anything in the HTML, but in the CSS write -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

// each box is 200px by 200px
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;

//  Change values 👇  to experiment
  <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<h2 id="heading-the-justify-content-property">The justify-content property</h2>
<p>You use this property to position your grid [Basically everything] inside the grid container along the <strong>X-Axis [Main Axis]</strong>. The <strong>7</strong> values are 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9a8eovy1t3i8x5yii4i.png" alt="Alt Text" width="1440" height="1024" loading="lazy"></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/onq2gubifwog2rccclqe.png" alt="Alt Text" width="1440" height="950" loading="lazy">
<em>justify-content</em></p>
<p>Don't change anything in the HTML, but in the CSS write -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

// each box is 200px by 200px
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;

//  Change  values  👇  to experiment
  <span class="hljs-attribute">justify-content</span>: center;
}
</code></pre>
<h2 id="heading-the-align-content-property">The align-content property</h2>
<p>You use this property to position our grid [Basically everything] inside the grid container along the <strong>Y-Axis [Cross Axis]</strong>. The <strong>7</strong> values are 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kfgzxrhe2ca4mzk1ies1.png" alt="Alt Text" width="1908" height="933" loading="lazy"></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1rjvr4bvwsc8ceevq96.png" alt="Alt Text" width="1317" height="1012" loading="lazy">
<em>align-content</em></p>
<p>Don't change anything in the HTML, but in the CSS write -&gt;</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

// each box is 200px by 200px
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">200px</span> <span class="hljs-number">200px</span>;

//  Change  values 👇  to experiment
  <span class="hljs-attribute">align-content </span>: center;
}
</code></pre>
<h1 id="heading-take-a-break">Take a Break</h1>
<p>So far so good! Take a break, you deserve it.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xanzksehasqcwc8qm8fw.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<h1 id="heading-css-grid-child-properties">CSS Grid Child Properties</h1>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k2k1muu9oldsp02aigvx.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<p>Now, let's look at Grid child properties.</p>
<h1 id="heading-the-css-grid-scale">The CSS Grid Scale</h1>
<p>I made this grid scale to demonstrate the calculations of how rows and columns are joined together. We can use any 1 of the 2 types of measurement:</p>
<ul>
<li>The digit [1,2,3,4, etc...]</li>
<li>The span keyword</li>
</ul>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ie4paaplgo8rwf4fd41o.png" alt="Alt Text" width="1288" height="997" loading="lazy">
<em>The Grid Scale</em></p>
<p>You'll get a clear picture of how this guide works ☝️ when we write code in just a short moment.</p>
<p>The illustration below 👇 shows the start and end points of rows and columns of a single cell.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bumrjjy06owkahoe49y3.png" alt="Alt Text" width="1440" height="763" loading="lazy">
<em>Grid column &amp; row -&gt; start &amp; end points</em></p>
<h3 id="heading-html-1">HTML</h3>
<p>To experiment with the grid scale and understand the following properties, make 4 boxes inside 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> A <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">"box-2"</span>&gt;</span> B <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">"box-3"</span>&gt;</span> C <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">"box-4"</span>&gt;</span> D <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>
<p>We're gonna utilize the <code>repeat()</code> function. It repeats our code a certain number of times. Here's an example 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span> : <span class="hljs-selector-tag">repeat</span>(5,1<span class="hljs-selector-tag">fr</span>);
</code></pre>
<p>This ☝️ is the equivalent to writing this:👇</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-columns</span> : 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span> 1<span class="hljs-selector-tag">fr</span> ;
</code></pre>
<h4 id="heading-a-quick-note">A Quick Note</h4>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i2q151726koc8h8mp0ht.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<p>When we use the fr [ Fraction ] unit, we are dividing the screen area into equal proportions.</p>
<pre><code class="lang-css">  <span class="hljs-selector-tag">grid-template-columns</span>: <span class="hljs-selector-tag">repeat</span>(5, 1<span class="hljs-selector-tag">fr</span>);
</code></pre>
<p>This ☝️ code is dividing our screen width into 5 equal parts.</p>
<p>We're set, let's start!</p>
<h2 id="heading-the-grid-column-startend-properties">The grid-column: start/end properties</h2>
<p>You use these two properties to join multiple <strong>COLUMNS</strong> together. It is a shorthand of 2 properties:</p>
<ul>
<li><strong>grid-column-start</strong></li>
<li><strong>grid-column-end</strong></li>
</ul>
<p>Write this code in your CSS:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">12</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">12</span>, <span class="hljs-number">1</span>fr);
}
</code></pre>
<p>The result looks like this:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2pt6zzl39mvjkv6h1m2.png" alt="Alt Text" width="692" height="206" loading="lazy"></p>
<p>Here, we are dividing our screen [ both width and height ] into 12 equal parts. 1 box is occupying 1 part, or you can call it 1fr [ 1 fraction ]. The remaining 8 fractions along the width are empty.</p>
<p>As we are dealing with child properties, we need to target our <code>.box-*</code> classes like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{}
<span class="hljs-selector-class">.box-2</span>{}
<span class="hljs-selector-class">.box-3</span>{}
<span class="hljs-selector-class">.box-4</span>{}
</code></pre>
<p>You can experiment with any or all of these boxes, I'll stick with <code>.box-1</code>.</p>
<p>Let's bring our grid scale. We are dealing with columns – just focus on the columns, not rows.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ie4paaplgo8rwf4fd41o.png" alt="Alt Text" width="1288" height="997" loading="lazy">
<em>The Grid Scale</em></p>
<p>The default scale of every <code>.box-*</code> class is:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-column-start</span> : 1;
<span class="hljs-selector-tag">grid-column-end</span> : 2;

<span class="hljs-comment">/* The shorthand -&gt; */</span>
 <span class="hljs-selector-tag">grid-column</span> : 1 / 2
</code></pre>
<p>We can write this ☝️ in the span unit as well, like this 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-column</span> : <span class="hljs-selector-tag">span</span> 1;
</code></pre>
<p>Let's assign the empty 8 fractions to <code>.box-1</code> like this 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
<span class="hljs-attribute">grid-column </span>: <span class="hljs-number">1</span>/<span class="hljs-number">10</span>
}
</code></pre>
<p>The result looks like this:👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zgcg4yyxourlpk1b6z3m.png" alt="Alt Text" width="713" height="198" loading="lazy"></p>
<h3 id="heading-a-quick-note-1">A quick note</h3>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g10ckpo6g3tpn8e9kkpw.png" alt="Alt Text" width="1185" height="555" loading="lazy"></p>
<p>How did I do the calculation? The <code>box-1</code> occupies 1 box itself. And over that, we are adding more 8 boxes. At the last, you must add 1 to indicate the end so, 8+1+1 = 10.</p>
<h3 id="heading-how-to-use-the-span-keyword">How to use the span keyword</h3>
<p>If you're confused by the first property, you can use the <code>span</code> keyword as it is easier to understand.</p>
<p>We need to add 8 boxes to <code>.box-1</code> which already occupies one box. So, we have to do 8+1 = 9.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
  <span class="hljs-attribute">grid-column </span>: span <span class="hljs-number">9</span>;
}
</code></pre>
<p>This is gonna output the same result.</p>
<h2 id="heading-the-grid-row-startend-properties">The grid-row: start/end properties</h2>
<p>You use these two properties to join multiple <strong>ROWS</strong> together. It is shorthand of 2 properties:</p>
<ul>
<li><strong>grid-row-start</strong></li>
<li><strong>grid-row-end</strong></li>
</ul>
<p>Let's experiment with it! Here, I'll stick with .box-1, and here's our grid guide. Now, only focus on the row scale, not the column.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ie4paaplgo8rwf4fd41o.png" alt="Alt Text" width="1288" height="997" loading="lazy">
<em>The Grid Scale</em></p>
<p>Let's join 9 boxes to <code>.box-1</code> along the row.</p>
<p>Write this code: 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
  <span class="hljs-attribute">grid-row </span>: <span class="hljs-number">1</span>/<span class="hljs-number">11</span>;
}
</code></pre>
<p>The calculation looks like this -&gt; <code>.box-1</code> holds 1 box, and you add 9 more boxes, plus a mandatory 1 at the last position to indicate the end which gives you 9+1+1=11.</p>
<p>Here's the alternative 👇 using the span keyword:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
  <span class="hljs-attribute">grid-row </span>: span <span class="hljs-number">10</span>;
}
</code></pre>
<p>And here's that calculation -&gt; <code>.box-</code>1 holds 1 box, and you add 9 more boxes<br>9+1=10.</p>
<p>Here's the result so far: 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqkoglmoh1whcyve7uad.png" alt="Alt Text" width="763" height="598" loading="lazy"></p>
<h2 id="heading-the-grid-area-property">The grid-area property</h2>
<p>First, we need to set up <a class="post-section-overview" href="#heading-the-grid-template-areas-property-1">grid-template-areas</a> ☝️ Once we've done that, we have to specify the names used in parent class inside the children classes, like this:👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcoalgwdeiogd3tmazzf.png" alt="Alt Text" width="1440" height="1024" loading="lazy">
<em>Standard 12X12 layout</em></p>
<p>Then we need to specify grid-template-areas inside parent container: 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3r84bvxt5230jyr5pydt.png" alt="Alt Text" width="1440" height="863" loading="lazy"></p>
<p>Like this 👇 inside the parent 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">gap</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

  <span class="hljs-attribute">grid-template-areas</span>: 
    <span class="hljs-string">"A A A A   A A A A   A A A A"</span>
    <span class="hljs-string">"B B B B   B B B B   B B C C"</span>
    <span class="hljs-string">"B B B B   B B B B   B B C C"</span>;
}
</code></pre>
<p>Then we specify the names used in the parent container inside the child classes with grid-areas👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffwg22949ogu0m2bw3sn.png" alt="Alt Text" width="1312" height="779" loading="lazy"></p>
<p>Like this 👇 inside the children classes:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span>{
  <span class="hljs-attribute">grid-area</span>: A;
}
<span class="hljs-selector-class">.box-2</span>{
  <span class="hljs-attribute">grid-area</span>: B;
}
<span class="hljs-selector-class">.box-3</span>{
  <span class="hljs-attribute">grid-area</span>: C;
}
</code></pre>
<h2 id="heading-the-justify-self-property">The justify-self property</h2>
<p>You use this property to position <strong>1 individual</strong> grid-item (child) inside a grid container along the <strong>X-Axis [Main Axis]</strong>. The <strong>4</strong> values are 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g21475dm64kw2vyqgxvd.png" alt="Alt Text" width="1484" height="979" loading="lazy">
<em>Justify-self</em></p>
<p>Write this code to experiment with the values 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap </span>:<span class="hljs-number">25px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

<span class="hljs-comment">/* // each box has equal size */</span>
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
}
</code></pre>
<p><strong>Remember!</strong> This only works on the child classes. So, target any <code>.box-*</code> class. I'll target the first box:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span> {
<span class="hljs-comment">/*  Change values 👇  to experiment */</span>
  <span class="hljs-attribute">justify-self </span>: start;  
}
</code></pre>
<h2 id="heading-the-align-self-property">The align-self property</h2>
<p>You use this property to position <strong>1 individual</strong> grid-item (child) inside a grid container along the <strong>Y-Axis [Cross Axis]</strong>. The <strong>4</strong> values are 👇</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qr5dlqehevjclxys3bx6.png" alt="Alt Text" width="1165" height="710" loading="lazy">
<em>align-self</em></p>
<p>Let's experiment with the values 👇</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap </span>:<span class="hljs-number">25px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;

<span class="hljs-comment">/* // each box has equal size */</span>
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">1</span>fr <span class="hljs-number">1</span>fr;
}
</code></pre>
<p><strong>Remember!</strong> This only works on the child classes. So, target any <code>.box-*</code> class. I'll target the 1st box:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.box-1</span> {
<span class="hljs-comment">/*  Change values 👇  to experiment */</span>
  <span class="hljs-attribute">align-self </span>: start;  
}
</code></pre>
<h1 id="heading-shorthand-for-css-grid-properties">Shorthand for CSS Grid Properties</h1>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f6s9qvnvjtwbj7r1ash6.png" alt="Alt Text" width="1030" height="600" loading="lazy"></p>
<p>Let's look at these Grid shorthand properties:</p>
<ul>
<li><code>place-content</code></li>
<li><code>place-items</code></li>
<li><code>place-self</code></li>
<li><code>grid-template</code></li>
<li><code>gap</code> / <code>grid-gap</code></li>
</ul>
<h2 id="heading-place-content">place-content</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jz1dydjbbgxw8bxt86i4.png" alt="Alt Text" width="1637" height="414" loading="lazy">
<em>place-content</em></p>
<p>This is the shorthand of 2 properties:</p>
<ul>
<li>align-content</li>
<li>justify-content</li>
</ul>
<h4 id="heading-an-example">An example</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-content</span> : <span class="hljs-selector-tag">center</span>;
<span class="hljs-selector-tag">justify-content</span> : <span class="hljs-selector-tag">end</span>;

<span class="hljs-comment">/* The shorthand */</span>
<span class="hljs-selector-tag">place-content</span> : <span class="hljs-selector-tag">center</span> / <span class="hljs-selector-tag">end</span> ;
</code></pre>
<h2 id="heading-place-items">place-items</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fvu44ujney5ixzvzedbb.png" alt="Alt Text" width="1440" height="414" loading="lazy">
<em>place-items</em></p>
<p>This is the shorthand of 2 properties:</p>
<ul>
<li>align-items</li>
<li>justify-items</li>
</ul>
<h4 id="heading-an-example-1">An example</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-items</span> : <span class="hljs-selector-tag">end</span>;
<span class="hljs-selector-tag">justify-items</span> : <span class="hljs-selector-tag">center</span>;

<span class="hljs-comment">/* The shorthand */</span>
<span class="hljs-selector-tag">place-items</span> : <span class="hljs-selector-tag">end</span> / <span class="hljs-selector-tag">center</span> ;
</code></pre>
<h2 id="heading-place-self">place-self</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jafsak8hqgfb78hbxs0b.png" alt="Alt Text" width="1225" height="414" loading="lazy">
<em>place-self</em></p>
<p>This is the shorthand of 2 properties:</p>
<ul>
<li>align-self</li>
<li>justify-self</li>
</ul>
<h4 id="heading-an-example-2">An example</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">align-self</span> : <span class="hljs-selector-tag">start</span> ;
<span class="hljs-selector-tag">justify-self</span> : <span class="hljs-selector-tag">end</span> ;

<span class="hljs-comment">/* The shorthand */</span>
<span class="hljs-selector-tag">place-self</span> : <span class="hljs-selector-tag">start</span> / <span class="hljs-selector-tag">end</span> ;
</code></pre>
<h2 id="heading-grid-template">grid-template</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dlratlmwgt0vvknnt82w.png" alt="Alt Text" width="2130" height="170" loading="lazy">
<em>grid-template</em></p>
<p>This is the shorthand of 2 properties:</p>
<ul>
<li>grid-template-rows</li>
<li>grid-template-columns</li>
</ul>
<h4 id="heading-an-example-3">An example</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">grid-template-rows</span> : 100<span class="hljs-selector-tag">px</span> 100<span class="hljs-selector-tag">px</span>;
<span class="hljs-selector-tag">grid-template-columns</span> : 200<span class="hljs-selector-tag">px</span> 200<span class="hljs-selector-tag">px</span>;

<span class="hljs-comment">/* The shorthand */</span>
<span class="hljs-selector-tag">grid-template</span> : 100<span class="hljs-selector-tag">px</span> 100<span class="hljs-selector-tag">px</span> / 200<span class="hljs-selector-tag">px</span> 200<span class="hljs-selector-tag">px</span>;
</code></pre>
<h2 id="heading-gapgrid-gap">gap/grid-gap</h2>
<p>Gap and grid-gap are the same thing and do the same work. You can use either of them.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brubmtmvt2jvq1l9f1ep.png" alt="Alt Text" width="1054" height="166" loading="lazy">
<em>gap</em></p>
<p>This is the shorthand of 2 properties:</p>
<ul>
<li>row-gap</li>
<li>column-gap</li>
</ul>
<h4 id="heading-an-example-4">An example</h4>
<pre><code class="lang-css"><span class="hljs-selector-tag">row-gap</span> : 20<span class="hljs-selector-tag">px</span> ; 
<span class="hljs-selector-tag">column-gap</span> : 30<span class="hljs-selector-tag">px</span> ;

<span class="hljs-comment">/* The shorthand */</span>
<span class="hljs-selector-tag">gap</span> : 20<span class="hljs-selector-tag">px</span>  30<span class="hljs-selector-tag">px</span>;
</code></pre>
<h2 id="heading-credits">Credits</h2>
<ul>
<li><a target="_blank" href="https://www.flaticon.com/packs/unicorn-4">Unicorns</a></li>
<li><a target="_blank" href="https://www.freepik.com/free-vector/cute-corgi-drink-milk-tea-boba-cartoon-vector-illustration-animal-drink-concept-isolated-vector-flat-cartoon-style_10336142.htm#position=13">Corgis</a>, <a target="_blank" href="https://www.freepik.com/free-psd/pet-food-banner-template_13762522.htm#position=1">kat</a></li>
</ul>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Now, you can confidently make responsive website layouts using your grid knowledge!</p>
<p>Here's your medal 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>
        
            <item>
                <title>
                    <![CDATA[ Learn CSS Grid by Building 5 Layouts in 17 minutes ]]>
                </title>
                <description>
                    <![CDATA[ By Thu Nghiem CSS Grid is a tool you can use to help create layouts for your website. It's especially useful if you need to think about the position, layers, or sizes of different elements. CSS Grid is complicated and there are many things to learn. ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-css-grid-by-building-5-layouts/</link>
                <guid isPermaLink="false">66d46153bd438296f45cd3c2</guid>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS Grid ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 27 Jan 2021 00:48:35 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/01/GridThumb.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Thu Nghiem</p>
<p>CSS Grid is a tool you can use to help create layouts for your website. It's especially useful if you need to think about the position, layers, or sizes of different elements.</p>
<p>CSS Grid is complicated and there are many things to learn. But the good news is that you don't need to know everything all at once. </p>
<p>In this tutorial, we will build 5 different layouts (which are explained as five separate tasks below) with CSS Grid. At the end of the tutorial, you will be ready to use CSS Grid in your next projects.</p>
<p>If you want to code along, be sure to download the resources:</p>
<ul>
<li><a target="_blank" href="https://bit.ly/38TbZum">Tasks-Design</a></li>
<li><a target="_blank" href="https://bit.ly/38MyQYy">CSS-Grid-Starter</a></li>
</ul>
<p>Here's a video you can watch if you want to supplement this article:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/CC2HkBZuReY" 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>Here are the first two layouts we'll build:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/xciaiefay1v6in3hegmw.png" alt="Alt Text" width="1261" height="641" loading="lazy">
<em>Task 1 and task 2</em></p>
<h2 id="heading-1-how-to-build-a-pancake-stack-with-css-grid">1: How to Build a Pancake Stack with CSS Grid</h2>
<p>For task number one, we need to create a pancake stack layout. To create this layout, we can make three rows by using <code>grid-template-rows: auto 1fr auto</code>. The second row with a value of <code>1fr</code> will expand as much as it can, whereas the other two only have enough space by wrapping their content.</p>
<p>So to achieve this layout, all we have to do is to give the container the following parameters:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-1</span><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>;

  <span class="hljs-attribute">grid-template-rows</span>: auto <span class="hljs-number">1</span>fr auto;
}
</code></pre>
<p>and you can see this layout everywhere, for example, in one of my tutorials:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/srqeinbsoirmayvi2uvf.png" alt="Alt Text" width="1400" height="959" loading="lazy"></p>
<p>Here's the <a target="_blank" href="https://youtu.be/d-qVF18Q7es">YouTube link</a> if you want to watch and code along.</p>
<h2 id="heading-2-how-to-build-a-simple-12-column-grid-layout-with-css-grid">2: How to Build a Simple 12 Column Grid Layout with CSS Grid</h2>
<p>The basic 12 column grid layout has been around forever. And with CSS Grid, it's even easier to use. In this simple task we need to give <code>item-1</code> four columns and <code>items-2</code> six columns.</p>
<p>First, we need to create 12 columns. We can do that with  <code>grid-template-columns: repeat(12, 1fr);</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-2</span><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>;

  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">12</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">column-gap</span>: <span class="hljs-number">12px</span>;

  <span class="hljs-attribute">align-items</span>: center;
}
</code></pre>
<p>Notice here that we also have the <code>12px</code> gap between every column. Similar to Flex, we also can use <code>align-items</code> and <code>justify-content</code>.</p>
<p>The next thing we need to do is to tell which column(s) the items should take up:</p>
<p>For item 1, we want it to start from column 2 and end at number 6. So we have:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-2</span> <span class="hljs-selector-class">.item-1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">2</span>;
  <span class="hljs-attribute">grid-column-end</span>: <span class="hljs-number">6</span>;
}
</code></pre>
<p>Notice that the item will not include column number 6, only columns 2, 3, 4, and 5.</p>
<p>We can also have the same affect by writing:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-2</span> <span class="hljs-selector-class">.item-1</span> {
  <span class="hljs-attribute">grid-column-start</span>: <span class="hljs-number">2</span>;
  <span class="hljs-attribute">grid-column-end</span>: span <span class="hljs-number">4</span>;
}
</code></pre>
<p>or</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-2</span> <span class="hljs-selector-class">.item-1</span> {
  <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">2</span> / span <span class="hljs-number">4</span>;
}
</code></pre>
<p>With the same logic, we will have the following for item 2:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-2</span> <span class="hljs-selector-class">.item-2</span> {
  <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">6</span> / span <span class="hljs-number">6</span>;
}
</code></pre>
<p>You can see 12 column layout are everywhere – here is a tutorial where I use this technique.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/bj6vyu3smpr4705k8ynq.png" alt="Alt Text" width="1442" height="1000" loading="lazy"></p>
<p>Here's the <a target="_blank" href="https://www.youtube.com/watch?v=XXDOUuzzUOY&amp;t=16s&amp;ab_channel=ThuNghiem">YouTube link</a> if you want to watch and code along.</p>
<h2 id="heading-3-how-to-build-a-responsive-layout-with-and-without-grid-template-areas">3:  How to Build a Responsive Layout with and without <code>grid-template-areas</code></h2>
<p>I am going to show you <em>two options</em> here. For the first option, we are going to use the 12 column grid that we learned from the 2nd task.</p>
<p>For the second option, we going to use a property called <code>grid-template-areas</code>.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/z65zhc0qjbotart85kny.png" alt="Alt Text" width="1264" height="1012" loading="lazy"></p>
<h3 id="heading-the-first-option-how-to-use-the-12-column-grid">The First option: How to Use the 12 Column Grid</h3>
<h4 id="heading-mobile">Mobile</h4>
<p>This is quite straightforward. We can use what we learned from task number one, and make the main section expand. We can also give the grid a <code>gap: 24px</code> as in desktop. There will be columns, not just rows:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-3-1</span><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>;

  <span class="hljs-attribute">grid-template-rows</span>: auto auto <span class="hljs-number">1</span>fr auto auto auto;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">24px</span>;
}
</code></pre>
<h4 id="heading-tablet">Tablet</h4>
<p>On a tablet, where the screen is wider than <code>720px</code>, we want to have 12 columns and 4 rows. The third row will expand as much as it can:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">720px</span>) {
  <span class="hljs-selector-class">.task-3-1</span><span class="hljs-selector-class">.container</span> {
    <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">12</span>, <span class="hljs-number">1</span>fr);
    <span class="hljs-attribute">grid-template-rows</span>: auto auto <span class="hljs-number">1</span>fr auto;
  }
}
</code></pre>
<p>Now that we have 12 columns, we need to tell how many columns should each item take up:</p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">720px</span>) {

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">header</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 12 <span class="hljs-selector-tag">columns</span>
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.header</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">12</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">navigation</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">also</span> <span class="hljs-selector-tag">takes</span> 12 <span class="hljs-selector-tag">columns</span>
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.navigation</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">12</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 10 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">start</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 3
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.main</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">3</span> / span <span class="hljs-number">10</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">takes</span> 2 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">start</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 1
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.sidebar</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">2</span>;
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">3</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">ads</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 2 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">start</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 1
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.ads</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">2</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 10 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">start</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 3
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.footer</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">3</span> / span <span class="hljs-number">10</span>;
  }
}
</code></pre>
<p>Notice here that we need to give <code>.task-3-1 .sidebar</code> <code>grid-row: 3;</code> because sidebar is after the <code>main</code> section in the DOM.</p>
<h4 id="heading-desktop">Desktop</h4>
<p>For the desktop view, we will work with a screen that is bigger than <code>1020px</code>. As we already have 12 columns, now we only need to tell how many columns it should use: </p>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1020px</span>) {

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">navigation</span> <span class="hljs-selector-tag">takes</span> 8 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">starting</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 3
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.navigation</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">3</span> / span <span class="hljs-number">8</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">main</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 8 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">starting</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 3
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.main</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">3</span> / span <span class="hljs-number">8</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">sidebar</span> <span class="hljs-selector-tag">starts</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">row</span> 2 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">ends</span> <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">row</span> 4
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.sidebar</span> {
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">2</span> / <span class="hljs-number">4</span>
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">ads</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 2 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">starting</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 11
  // <span class="hljs-selector-tag">it</span> <span class="hljs-selector-tag">also</span> <span class="hljs-selector-tag">takes</span> 2 <span class="hljs-selector-tag">rows</span> <span class="hljs-selector-tag">starting</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">row</span> 2 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">ending</span> <span class="hljs-selector-tag">at</span> <span class="hljs-selector-tag">row</span> 4
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.ads</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">11</span> / span <span class="hljs-number">2</span>;
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">2</span> / <span class="hljs-number">4</span>;
  }

  // <span class="hljs-selector-tag">The</span> <span class="hljs-selector-tag">footer</span> <span class="hljs-selector-tag">section</span> <span class="hljs-selector-tag">takes</span> 12 <span class="hljs-selector-tag">columns</span> <span class="hljs-selector-tag">start</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 1
  <span class="hljs-selector-class">.task-3-1</span> <span class="hljs-selector-class">.footer</span> {
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">12</span>;
  }
}
</code></pre>
<h3 id="heading-real-life-example">Real life example</h3>
<p>You can actually find a similar layout on Dev.to's homepage:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/Screenshot-2021-01-27-at-0.36.34.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-the-second-option-how-to-use-grid-template-areas">The Second Option: How to Use <code>grid-template-areas</code></h3>
<p>Before using <code>grid-template-areas</code>, we need to define the area of the item using <code>grid-area</code>:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-3-2</span> <span class="hljs-selector-class">.header</span> {
  <span class="hljs-attribute">grid-area</span>: header;
}

<span class="hljs-selector-class">.task-3-2</span> <span class="hljs-selector-class">.navigation</span> {
  <span class="hljs-attribute">grid-area</span>: nav;
}

<span class="hljs-selector-class">.task-3-2</span> <span class="hljs-selector-class">.ads</span> {
  <span class="hljs-attribute">grid-area</span>: ads;
}

<span class="hljs-selector-class">.task-3-2</span> <span class="hljs-selector-class">.sidebar</span> {
  <span class="hljs-attribute">grid-area</span>: sidebar;
}

<span class="hljs-selector-class">.task-3-2</span> <span class="hljs-selector-class">.main</span> {
  <span class="hljs-attribute">grid-area</span>: main;
}

<span class="hljs-selector-class">.task-3-2</span> <span class="hljs-selector-class">.footer</span> {
  <span class="hljs-attribute">grid-area</span>: footer;
}
</code></pre>
<p>After the item areas are defined, all we have to do is to give the container the position by using <code>grid-template-areas</code>:</p>
<h4 id="heading-mobile-1">Mobile</h4>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-3-2</span><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>;

  <span class="hljs-attribute">gap</span>: <span class="hljs-number">24px</span>;

  // Creating 6 rows and 3rd row expands as much as it can  
  <span class="hljs-attribute">grid-template-rows</span>: auto auto <span class="hljs-number">1</span>fr auto auto auto;

  // Defining the template
  <span class="hljs-attribute">grid-template-areas</span>:
    <span class="hljs-string">"header"</span>
    <span class="hljs-string">"nav"</span>
    <span class="hljs-string">"main"</span>
    <span class="hljs-string">"sidebar"</span>
    <span class="hljs-string">"ads"</span>
    <span class="hljs-string">"footer"</span>;
}
</code></pre>
<p>So on mobile, we create 1 column and 6 rows. And row number 3, which is the main row, should expand as much as it can.</p>
<p>This also makes it easy if, later on, you want to change the order/position of the item. For example, if we want to have navigation before the header we can do: </p>
<pre><code class="lang-css">...
 <span class="hljs-selector-tag">grid-template-areas</span>:
    "<span class="hljs-selector-tag">nav</span>"
    "<span class="hljs-selector-tag">header</span>"
    "<span class="hljs-selector-tag">main</span>"
    "<span class="hljs-selector-tag">sidebar</span>"
    "<span class="hljs-selector-tag">ads</span>"
    "<span class="hljs-selector-tag">footer</span>";
...
</code></pre>
<h4 id="heading-tablet-1">Tablet</h4>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">720px</span>) {
  <span class="hljs-selector-class">.task-3-2</span><span class="hljs-selector-class">.container</span> {
    // Creating 4 rows and the 3rd row expands as much as it can
    <span class="hljs-attribute">grid-template-rows</span>: auto auto <span class="hljs-number">1</span>fr auto;

    // Defining the template (3 columns)
    <span class="hljs-attribute">grid-template-areas</span>:
      <span class="hljs-string">"header header header"</span>
      <span class="hljs-string">"nav nav nav "</span>
      <span class="hljs-string">"sidebar main main"</span>
      <span class="hljs-string">"ads footer footer"</span>;
  }
}
</code></pre>
<p>With the code above, if the screen is wider than 720px we want to create 3 columns and 4 rows. The header and the navigation both take up 3 columns.</p>
<p>On the third and fourth row, the sidebar and ads take 1 column, whereas, the main and footer take 2 columns.</p>
<h4 id="heading-desktop-1">Desktop</h4>
<pre><code class="lang-css"><span class="hljs-keyword">@media</span> (<span class="hljs-attribute">min-width:</span> <span class="hljs-number">1020px</span>) {
  <span class="hljs-selector-class">.task-3-2</span><span class="hljs-selector-class">.container</span> {
    // Creating 4 rows and the 3rd row expands as much as it can
    <span class="hljs-attribute">grid-template-rows</span>: auto auto <span class="hljs-number">1</span>fr auto;

    // Defining the template (4 columns)
    <span class="hljs-attribute">grid-template-areas</span>:
      <span class="hljs-string">"header header header header"</span>
      <span class="hljs-string">"sidebar nav nav ads"</span>
      <span class="hljs-string">"sidebar main main ads"</span>
      <span class="hljs-string">"footer footer footer footer"</span>;
  }
}
</code></pre>
<p>Here we find similar logic to tablet view. For the desktop, we create 4 columns and 4 rows and the placement according to the value of <code>grid-template-areas</code>.</p>
<h3 id="heading-which-should-you-choose">Which should you choose?</h3>
<p><strong>Using</strong> <strong>the</strong> <strong>12 Column Grid</strong>:</p>
<p>➕  Easy and fast to start 
➕  Easy to maintain for column-focused layouts
➖  Difficult to arrange items in complex layouts</p>
<p>You should use 12 Column Grid for less complex layouts that focus mainly on the arrangement of the columns.</p>
<p><strong>Using</strong> <code>**grid-template-areas**</code>:</p>
<p>➕ Flexible for complex layouts
➕ Easy to visualize 
➖ Takes more time to implement</p>
<p>You should use <code>grid-template-areas</code> for more complex layouts where you need to care about positions or sizes of many elements.</p>
<p>Both options have pros and cons, but you should choose the one that's easier for you and makes sense in your particular scenario.</p>
<h2 id="heading-4-how-to-build-a-responsive-layout-without-media-queries-in-css-grid">4: How to Build a Responsive Layout Without Media Queries in CSS Grid</h2>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/i/61w4dsetc7xtq4uspz8v.png" alt="Alt Text" width="1277" height="579" loading="lazy"></p>
<p>It is surprisingly simple to do this. We can make it happen with one line of code: <code>grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));</code>, like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-4</span><span class="hljs-selector-class">.container</span> {
  <span class="hljs-attribute">display</span>: grid;
  <span class="hljs-attribute">gap</span>: <span class="hljs-number">24px</span>;

  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(auto-fill, minmax(<span class="hljs-number">150px</span>, <span class="hljs-number">1</span>fr));
}
</code></pre>
<p>We just created a flexible column layout and specified that the column should never be less than 150px and should share the space evenly.</p>
<h2 id="heading-5-how-to-build-a-12-x-12-chess-grid-with-css-grid">5: How to Build a 12 x 12 Chess Grid with CSS Grid</h2>
<p>For the last task, I want to show you that, not only we can define the number of columns, but we can also define the number of rows using CSS Grid.</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.task-5</span><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>;

  <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">12</span>, <span class="hljs-number">1</span>fr);
  <span class="hljs-attribute">grid-template-rows</span>: <span class="hljs-built_in">repeat</span>(<span class="hljs-number">12</span>, <span class="hljs-number">1</span>fr);
}
</code></pre>
<p>Now, we can place the items anywhere we want. So to create this layout:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/01/Screenshot-2021-01-27-at-0.49.40.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We can do this: </p>
<pre><code class="lang-css">...
// <span class="hljs-selector-tag">First</span> <span class="hljs-selector-tag">item</span> <span class="hljs-selector-tag">starts</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 1 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
// <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">row</span> 1 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
<span class="hljs-selector-class">.task-5</span> <span class="hljs-selector-class">.item-1</span> {
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">3</span>;
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">3</span>;
}

// <span class="hljs-selector-tag">Second</span> <span class="hljs-selector-tag">item</span> <span class="hljs-selector-tag">starts</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 4 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
// <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">row</span> 4 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
<span class="hljs-selector-class">.task-5</span> <span class="hljs-selector-class">.item-2</span> {
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">4</span> / span <span class="hljs-number">3</span>;
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">4</span> / span <span class="hljs-number">3</span>;
}

// <span class="hljs-selector-tag">First</span> <span class="hljs-selector-tag">item</span> <span class="hljs-selector-tag">starts</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 7 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
// <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">row</span> 7 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
<span class="hljs-selector-class">.task-5</span> <span class="hljs-selector-class">.item-3</span> {
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">7</span> / span <span class="hljs-number">3</span>;
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">7</span> / span <span class="hljs-number">3</span>;
}

// <span class="hljs-selector-tag">First</span> <span class="hljs-selector-tag">item</span> <span class="hljs-selector-tag">starts</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">column</span> 10 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
// <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">from</span> <span class="hljs-selector-tag">row</span> 10 <span class="hljs-selector-tag">and</span> <span class="hljs-selector-tag">expand</span> 3 <span class="hljs-selector-tag">columns</span>
<span class="hljs-selector-class">.task-5</span> <span class="hljs-selector-class">.item-4</span> {
    <span class="hljs-attribute">grid-row</span>: <span class="hljs-number">10</span> / span <span class="hljs-number">3</span>;
    <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">10</span> / span <span class="hljs-number">3</span>;
}
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Thanks for reading this article. This topic belongs to the series of videos that I will update on <a target="_blank" href="https://learn.devchallenges.io/">Learn.DevChallenges.io</a>. So to say updated, follow me on social media or subscribe to my <a target="_blank" href="https://www.youtube.com/channel/UCmSmLukBF--YrKZ2g4akYAQ?sub_confirmation=1">Youtube Channel</a>. Otherwise, happy coding and see you in the next video and articles 👋.</p>
<h2 id="heading-about-me"><strong><strong>__</strong></strong> 🐣 About me <strong><strong>__</strong></strong></h2>
<p>I am a full-stack developer, a UX/UI designer and a content creator. You can get to know me more in this short video:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/qCkmFd-72JY" 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>
<ul>
<li>I am the founder of <a target="_blank" href="https://devchallenges.io/">DevChallenges</a></li>
<li>Subscribe my <a target="_blank" href="https://www.youtube.com/channel/UCmSmLukBF--YrKZ2g4akYAQ?sub_confirmation=1">Youtube Channel</a></li>
<li>Follow my <a target="_blank" href="https://twitter.com/thunghiemdinh">Twitter</a></li>
<li>Join <a target="_blank" href="https://discord.com/invite/3R6vFeM">Discord</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
