<?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" version="2.0"><channel><title><![CDATA[Hardeborlaa's blog]]></title><description><![CDATA[Hardeborlaa's blog]]></description><link>https://hardeborlaa.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 20:07:26 GMT</lastBuildDate><atom:link href="https://hardeborlaa.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding the use of Order and Grid-template-area in CSS]]></title><description><![CDATA[Have you ever been in a situation whereby you want to change the visual order of your elements without re-ordering the HTML file? If yes, then this article is for you. Keep reading. I will explain how it works.
Order
CSS order is used to change the v...]]></description><link>https://hardeborlaa.hashnode.dev/understanding-the-use-of-order-and-grid-template-area-in-css</link><guid isPermaLink="true">https://hardeborlaa.hashnode.dev/understanding-the-use-of-order-and-grid-template-area-in-css</guid><category><![CDATA[grid]]></category><category><![CDATA[flexbox]]></category><category><![CDATA[css flexbox]]></category><category><![CDATA[CSS]]></category><dc:creator><![CDATA[Opeyemi Adeleye]]></dc:creator><pubDate>Fri, 04 Nov 2022 14:30:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/d-1FY75fh_s/upload/v1667529195338/uNtDfr87m.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever been in a situation whereby you want to change the visual order of your elements without re-ordering the HTML file? If yes, then this article is for you. Keep reading. I will explain how it works.</p>
<h1 id="heading-order">Order</h1>
<p>CSS order is used to change the visual order of elements in a flex-box container. Order property is a sub-property of the flex-box. By default, the order property has a value of zero. It takes up either positive or negative values. The flex-items are displayed in the same order but with order property, it can be changed.</p>
<h2 id="heading-syntax">Syntax</h2>
<pre><code>order: <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">number</span>&gt;</span></span>
</code></pre><h2 id="heading-how-to-apply-for-an-order-in-flex-box">How to apply for an order in flex-box</h2>
<p>An HTML document will be needed to work with if you'd like to use the order property. An element will be defined to be the flex container and there will be flex items in the container. Exploring some code will help you learn fast, Check out the HTML below, </p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"container"</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">"flex-items"</span>&gt;</span>A<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>B<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>C<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>D<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>E<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>F<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/div&gt;
</code></pre><p>Just as you expect, let's add some little styling to get a better understanding</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">display</span>: flex;
    justify-content: space-evenly;
    background-color: rgb(<span class="hljs-number">164</span>, <span class="hljs-number">142</span>, <span class="hljs-number">224</span>);
}
.flex-items {
    background-color: rgb(<span class="hljs-number">14</span>, <span class="hljs-number">14</span>, <span class="hljs-number">173</span>);
    color: #fff;
    padding: <span class="hljs-number">30</span>px;
    font-size: <span class="hljs-number">2.2</span>em;
    margin: <span class="hljs-number">10</span>px;
    width: <span class="hljs-number">100</span>px;
    min-height: <span class="hljs-number">100</span>px;
}
</code></pre><p>Here is the result of the above code:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667555489257/DBiiIHlNT.png" alt="big.png" /></p>
<p>In a situation whereby you want A to come last and E to come second, F 
to come first without changing the source code in the HTML document, meaning you do not get to do this:</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"container"</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">"flex-items"</span>&gt;</span>F<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>E<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>C<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>D<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>B<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"flex-items"</span>&gt;</span>A<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/div&gt;
</code></pre><p>Now that is where the order property comes in. It would help if you made the order value of the flex item higher than the other items. Flex items are ordered from lowest to highest. Knowing that the flex-items have a default value of zero(0).</p>
<p>Therefore giving the flex-items, respective order properties will help reorder the items in the container as shown below:</p>
<pre><code>.flex-items:nth-child(<span class="hljs-number">1</span>){
    <span class="hljs-attr">order</span>: <span class="hljs-number">5</span>
}
.flex-items:nth-child(<span class="hljs-number">2</span>){
    <span class="hljs-attr">order</span>:<span class="hljs-number">4</span>
}
.flex-items:nth-child(<span class="hljs-number">3</span>){
    <span class="hljs-attr">order</span>:<span class="hljs-number">2</span>
}
.flex-items:nth-child(<span class="hljs-number">4</span>){
    <span class="hljs-attr">order</span>:<span class="hljs-number">3</span>
}
.flex-items:nth-child(<span class="hljs-number">5</span>){
    <span class="hljs-attr">order</span>:<span class="hljs-number">1</span>
}
.flex-items:nth-child(<span class="hljs-number">6</span>){
    <span class="hljs-attr">order</span>:<span class="hljs-number">0</span>
}
</code></pre><p>Here is the result after applying the order property:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667517595236/twmfhnfBV.png" alt="order2.png" /></p>
<p>To better understand the order property concept, here is another example</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"container"</span>&gt;
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>This is heading one<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the first paragraph<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>This is heading two<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span>
 &lt;/div&gt;
</code></pre><p>The style applied goes thus:</p>
<pre><code>.container {
    <span class="hljs-attr">display</span>: flex;
    flex-direction: column;
    align-items: center;
    background-color: rgb(<span class="hljs-number">164</span>,<span class="hljs-number">142</span>,<span class="hljs-number">244</span>);
    color: #fff;
    height: <span class="hljs-number">100</span>px;
    width: <span class="hljs-number">100</span>%;
}
</code></pre><p>The result goes thus: 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667518500050/S9GDeuXa-.png" alt="color.png" /></p>
<p>Therefore when order is applied, </p>
<pre><code>h1 {
    <span class="hljs-attr">order</span>: <span class="hljs-number">2</span>;
}
p {
    <span class="hljs-attr">order</span>: <span class="hljs-number">0</span>;
    margin-top: <span class="hljs-number">10</span>px;
}
h2 {
    <span class="hljs-attr">order</span>: <span class="hljs-number">1</span>;
}
</code></pre><p>The result goes thus thereby:
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667518674133/vEwgKcpi3.png" alt="color3.png" /></p>
<p>What happens in a situation whereby two flex-items have the same order value?
In the example below, flex-item 1 and 3 are given the same order values</p>
<pre><code>h1 {
    <span class="hljs-attr">order</span>: <span class="hljs-number">1</span>;
}
p {
    <span class="hljs-attr">order</span>: <span class="hljs-number">0</span>;
    margin-top: <span class="hljs-number">10</span>px;
}
h2 {
    <span class="hljs-attr">order</span>: <span class="hljs-number">1</span>;
}
</code></pre><p>Flex-item 3(h2) appears last because it comes after flex-item 1 (h1) which is based on the positions in the source file (HTML document), the items are still arranged from the lowest to the highest order.</p>
<h1 id="heading-grid-template-areas">Grid-template-areas</h1>
<p>The grid-template-areas property specifies areas within the grid layout. Grid items can be named by using the grid-area property and reference to the name in the grid-template-areas property. The grid-template property can be used as a shorthand to define the sizes of the columns and rows. </p>
<h2 id="heading-syntax">Syntax</h2>
<pre><code><span class="hljs-comment">/* Keyword value */</span>
grid-template-areas: none;

<span class="hljs-comment">/* &lt;string&gt; values */</span>
grid-template-areas: <span class="hljs-string">"a b"</span>;
grid-template-areas:
  <span class="hljs-string">"a b b"</span>
  <span class="hljs-string">"a c d"</span>;

<span class="hljs-comment">/* Global values */</span>
grid-template-areas: inherit;
grid-template-areas: initial;
grid-template-areas: revert;
grid-template-areas: revert-layer;
grid-template-areas: unset
</code></pre><h2 id="heading-formal-syntax">Formal syntax</h2>
<pre><code>grid-template-areas = 
  none       |
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">string</span>&gt;</span>+</span>
</code></pre><p>The grid-template-areas utilizes the areas in the grid container, each grid item can be assigned a name with the grid-area property. </p>
<p><strong><em> display: grid</em> </strong> must be set in the grid container for these properties to work</p>
<h2 id="heading-how-to-apply-css-grid-template-areas">How to apply CSS grid-template-areas</h2>
<p>It is beneficial to build a CSS grid template and name your CSS grid template areas in two steps as explained below;</p>
<ol>
<li>Define the names of your grid template areas with the grid-area property.
The common grid template areas to specify include header, footer, sidebar, content e.t.c</li>
<li>Use the grid-template-areas property to define how the areas appear in the rows and columns.</li>
</ol>
<h3 id="heading-here-is-an-example">Here is an example:</h3>
<p>(i) <strong>HTML documents that show the grid container and grid items</strong></p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"wrapper"</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">"header"</span>&gt;</span>Header<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"sidebar"</span>&gt;</span>Sidebar<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"content"</span>&gt;</span>Content<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"footer"</span>&gt;</span>Footer<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
 &lt;/div&gt;
</code></pre><p>(ii) <strong>Names of grid template areas defined with the grid-area property</strong></p>
<pre><code>.header {
  grid-area: hd;
  background-color: rgb(<span class="hljs-number">15</span>, <span class="hljs-number">15</span>, <span class="hljs-number">247</span>);
}
.footer {
  grid-area: ft;
  background-color: rgb(<span class="hljs-number">4</span>, <span class="hljs-number">97</span>, <span class="hljs-number">4</span>);
}
.content {
  grid-area: main;
  background-color: rgb(<span class="hljs-number">121</span>, <span class="hljs-number">5</span>, <span class="hljs-number">121</span>);
}
.sidebar {
  grid-area: sd;
  background-color: rgb(<span class="hljs-number">88</span>, <span class="hljs-number">88</span>, <span class="hljs-number">42</span>);
}
</code></pre><p>(iii) <strong>Grid template area defining how areas appear in rows and columns. 
</strong></p>
<pre><code>.wrapper {
  <span class="hljs-attr">display</span>: grid;
  grid-template-columns: repeat(<span class="hljs-number">9</span>, <span class="hljs-number">1</span>fr);
  grid-auto-rows: minmax(<span class="hljs-number">100</span>px, auto);
  grid-template-areas:
    <span class="hljs-string">"hd hd hd hd   hd   hd   hd   hd   hd"</span>
    <span class="hljs-string">"sd sd sd main main main main main main"</span>
    <span class="hljs-string">"ft ft ft ft   ft   ft   ft   ft   ft"</span>;
  color: #fff;
  font-size: <span class="hljs-number">1.5</span>em;
}
</code></pre><p>The first line command sets the display as a grid, the following line command defined columns as "9" items long, the following line command set the row and the last line gives the grid template area its arrangement. The grid template areas made use of the content areas names that were defined earlier, where the header <code>hd</code> gets all nine widths in the column, the next row which contains three <code>sd</code>(sidebar) and six "main"(content) making a total of nine on that row, the third row which is the (footer) <code>ft</code> takes up the whole nine-column width. </p>
<p>(iv) <strong>Here is the result</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667555572188/U7TMuSluQ.png" alt="bigger.png" /></p>
<h3 id="heading-below-is-another-example">Below is another example</h3>
<p>(i) <strong>HTML document with container class</strong></p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"grid-container"</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">"grid-item-one"</span>&gt;</span>Header<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid-item-two"</span>&gt;</span>Main<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid-item-three"</span>&gt;</span>Content<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
        <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"grid-item-four"</span>&gt;</span>Footer<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
&lt;/div&gt;
</code></pre><p>(ii) <strong>Grid template defined with grid areas</strong></p>
<pre><code>.grid-item-one {
  grid-area: head;
  background-color: rgb(<span class="hljs-number">13</span>, <span class="hljs-number">238</span>, <span class="hljs-number">238</span>);
}
.grid-item-two {
  grid-area: main;
  background-color: rgb(<span class="hljs-number">154</span>, <span class="hljs-number">55</span>, <span class="hljs-number">247</span>);
}
.grid-item-three {
  grid-area: side;
  background-color: rgb(<span class="hljs-number">160</span>, <span class="hljs-number">36</span>, <span class="hljs-number">36</span>);
}
.grid-item-four{
  grid-area: footer;
  background-color: rgb(<span class="hljs-number">53</span>, <span class="hljs-number">53</span>, <span class="hljs-number">252</span>);
}
</code></pre><p>(iii) <strong>Defining how areas appear in rows and columns. The dot <code>.</code> represents an empty grid shell.</strong></p>
<pre><code>.grid-container {
  <span class="hljs-attr">display</span>: grid;
  grid-template-columns: <span class="hljs-number">2</span>fr <span class="hljs-number">2</span>fr <span class="hljs-number">1</span>fr <span class="hljs-number">2</span>fr;
  grid-template-rows: <span class="hljs-number">100</span>px <span class="hljs-number">200</span>px <span class="hljs-number">100</span>px;
  grid-template-areas:
    <span class="hljs-string">"head head . side"</span>
    <span class="hljs-string">"main main main side"</span>
    <span class="hljs-string">". footer footer footer"</span>;
  color: #fff;
  font-size: <span class="hljs-number">1.5</span>em;
  text-align: center;
}
</code></pre><p>(iv) <strong>Here is the result:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1667553818602/ZfWvr9qv7.png" alt="grido.png" /></p>
<h2 id="heading-resources">Resources</h2>
<p>For more information, Check out:</p>
<p><a target="_blank" href="Link">https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-areas</a></p>
<p><a target="_blank" href="Link">https://developer.mozilla.org/en-US/docs/Web/CSS/order</a></p>
<p><a target="_blank" href="Link">https://css-tricks.com/almanac/properties/o/order/</a></p>
<p><a target="_blank" href="Link">https://css-tricks.com/almanac/properties/g/grid-template-areas/</a></p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>In this article, you learned all the specifics needed to use CSS order and grid-template-area. Here is a summary of everything you've learned in this article: </p>
<ul>
<li><p>CSS order changes the visual representation, not the HTML source.</p>
</li>
<li><p>CSS order accepts a number as its value.</p>
</li>
<li><p>CSS grid-template-area changes the visual representation of the grid with the help of columns and rows</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>