avatarEmily Y Leung

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

4031

Abstract

-number">1000px</span>; <span class="hljs-attribute">margin</span>: <span class="hljs-number">200px</span> auto; <span class="hljs-attribute">grid-gap</span>: <span class="hljs-number">10px</span> <span class="hljs-number">50px</span>; <span class="hljs-attribute">grid-template-columns</span>: <span class="hljs-number">3</span>fr <span class="hljs-number">12</span>fr <span class="hljs-number">4</span>fr <span class="hljs-number">5</span>fr; }</pre></div><div id="44eb"><pre><span class="hljs-selector-class">.post</span> > * { <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">2</span> / -<span class="hljs-number">2</span>; }</pre></div><figure id="409e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*qU2It9di2_jh-k_P2Cnsnw.png"><figcaption></figcaption></figure><h1 id="f148">Figure Images and Captions</h1><p id="f301">The HTML structure of the figure looks like this:</p><div id="501f"><pre><article <span class="hljs-attribute">class</span>=<span class="hljs-string">"post"</span>></pre></div><div id="fcab"><pre> ...</pre></div><div id="3ba5"><pre> <span class="hljs-tag"><<span class="hljs-name">figure</span>></span> <span class="hljs-tag"><<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">""</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Big Image"</span>></span> <span class="hljs-tag"><<span class="hljs-name">figcaption</span>></span>Super Nice Photo<span class="hljs-tag"></<span class="hljs-name">figcaption</span>></span> <span class="hljs-tag"></<span class="hljs-name">figure</span>></span></pre></div><div id="e608"><pre> <span class="hljs-string">...</span> <<span class="hljs-string">/article</span>></pre></div><figure id="342f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*X-UZri0wN7gWvoTuLDm-Hg.png"><figcaption></figcaption></figure><p id="4f08">We want to span the image across all columns, to do this:</p><ul><li>Remove the <code>margin</code></li><li>Position the start and stop of the <code>grid-column</code> to the entirety of the grid</li><li>Style the caption</li></ul><div id="665c"><pre><span class="hljs-selector-class">.post</span> > <span class="hljs-selector-tag">figure</span> { <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>; <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / -<span class="hljs-number">1</span>; }</pre></div><div id="d2d4"><pre><span class="hljs-selector-tag">figcaption</span> { <span class="hljs-attribute">font-size</span>: <span class="hljs-number">10px</span>; }</pre></div><figure id="82f1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*3tuEVcdYRNIMkhLdl41l3Q.png"><figcaption></figcaption></figure><h1 id="a8f6">Styling Blockquotes</h1><p id="c8e4">Similar to the figure images, we’ll span the blockquote to the start and end columns of the grid, and add:</p><ul><li><code>font-size</code> of 60px</li><li><code>font-style</code> of italic</li><li><code>text-align</code> it to the centre</li><li>Remove the <code>margin</code></li></ul><div id="57da"><pre><span class="hljs-selector-class">.post</span> > <span class="hljs-selector-tag">blockquote</span> { <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>; <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / -<span class="hljs-number">1</span>; <span class="hljs-attribute">font-size</span>: <span class="hljs-number">60px</span>; <span class="hljs-attribute">font-style</span>: italic; <span class="hljs-attribute">text-align</span>: center; }</pre></div><figure id="af96"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*mAtW7AtD7HV6gg68wmMnqg.png"><figcaption></figcaption></figure><p id="3186">Finally, we’ve got these tips that will sit on either the left of right column

Options

gutters.</p><p id="9ace">To style the tips, add:</p><ul><li><code>background</code> of <code>#FAFAFA</code></li><li>a <code>padding</code> 10px</li></ul><div id="e6f1"><pre><span class="hljs-selector-class">.tip</span> { <span class="hljs-attribute">background</span>: <span class="hljs-number">#FAFAFA</span>; <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>; }</pre></div><figure id="a4fb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*AG66l96_gXAA5j-Xw8fq3w.png"><figcaption></figcaption></figure><p id="c45a">The left and right tips will have slightly different styling to suit its position.</p><p id="bf05">So for the tips called with <code>tip-left</code>, we’ll apply the following:</p><ul><li><code>grid-column</code> to start on the first column and span 1 column</li><li><code>text-align</code> to the right</li><li>add a <code>border-right</code> with a solid yellow line of 2px</li></ul><div id="4efc"><pre><span class="hljs-selector-class">.tip-left</span> { <span class="hljs-attribute">grid-column</span>: <span class="hljs-number">1</span> / span <span class="hljs-number">1</span>; <span class="hljs-attribute">text-align</span>: right; <span class="hljs-attribute">border-right</span>: <span class="hljs-number">2px</span> solid <span class="hljs-built_in">var</span>(--yellow); }</pre></div><p id="0488">When we move the tip to the first column, this means that the content below will shift up in line with the tip.</p><figure id="4601"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*BIcIVAvECG1b_8VFbYcyYA.png"><figcaption></figcaption></figure><p id="b488">Similarly, we’ll apply styling to the right, but arranging it in the opposite direction.</p><div id="3dba"><pre><span class="hljs-selector-class">.tip-right</span> { <span class="hljs-attribute">grid-column</span>: span <span class="hljs-number">1</span> / -<span class="hljs-number">1</span>; <span class="hljs-attribute">border-left</span>: <span class="hljs-number">2px</span> solid <span class="hljs-built_in">var</span>(--yellow); }</pre></div><figure id="d62c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*CxOxpefon-6q_TO5i_uLUw.png"><figcaption></figcaption></figure><p id="1ded">One thing to note is that if the tip has beyond a certain amount of content than it’s adjacent grid item, it will stretch the row causing a massive gap in the centre column. Like so:</p><figure id="5b0d"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*CjQtoJS4ZIp7FTDWXzy7Lw.png"><figcaption></figcaption></figure><p id="bdfe">A way around this is to increase the number of <code>grid-rows</code> from a default of 1 to say 5</p><div id="1946"><pre><span class="hljs-selector-class">.tip</span> { <span class="hljs-attribute">background</span>: <span class="hljs-number">#FAFAFA</span>; <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>; <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">5</span>; }</pre></div><figure id="dc15"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*YEfVHGzjWOHxnR8jycqJPA.png"><figcaption></figcaption></figure><p id="32fe">But this will cause other tips to stretch. To stretch only to its content, we can then <code>align-self</code> at the start.</p><div id="5f7e"><pre><span class="hljs-selector-class">.tip</span> { <span class="hljs-attribute">background</span>: <span class="hljs-number">#FAFAFA</span>; <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span>; <span class="hljs-attribute">grid-row</span>: span <span class="hljs-number">5</span>; <span class="hljs-attribute">align-self</span>: start; }</pre></div><p id="5992">Below is the final result, which concludes the CSS Grid Series.</p><figure id="0913"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*ZVXfdIxAniaO6nEXUWY92g.png"><figcaption></figcaption></figure></article></body>

CSS Grid (Part 23)— Full Bleed Blog Layout

Project case study — Building a responsive blog layout

Live dev notes taken throughout the CSS Grid course by Wesbos — cssgrid.io

Today we look at building a Full Bleed Blog Layout inspired by Phillipp Rudloff.

Wesbos has provided us with a single base HTML file which also houses the base CSS at the bottom.

Below is what we’re working with.

CSS grid has shown it’s capabilities in application layouts, but in this project we tap into the benefits of using it for laying out text on a page.

To do this, we’ll turn the post into a grid with 3 columns, where:

  • Most of the content is going to fill up the centre column
  • Occasionally images are going to spill out across the 3 columns with a figure caption
  • Blockquotes are styled to stand out
  • divs classed as tip will sit on either the left or right side of the main centre content column

Set up the grid

To begin, we’ll first apply the following to our article element classed as post:

  • display of grid
  • max-width of 1000px
  • margin of 200px (top/bottom) and auto (left/right)
  • grid-gap of 10px (horizontally) and 50px (vertically)
  • grid-template-columns of 3fr, 12fr and 5fr to make up the 3 grid column
.post {
    display: grid;
    max-width: 1000px;
    margin: 200px auto;
    grid-gap: 10px 50px;
    grid-template-columns: 3fr 12fr 5fr;
}

Notice is that each piece of content has been placed in order of the grid using up every empty spot.

What we want to do instead is select all elements and place them only in the centre column for now. This means, every child of the post will start at column 2 and span across 1 column.

.post > * {
    grid-column: 2 / span 1;
}

Similarly, we can write this:

.post > * {
    grid-column: 2 / -2;
}

Which is the preferred option because of the fact that if you added a fourth column, the span of the main content would fill all columns that are in the middle. For example:

.post {
    display: grid;
    max-width: 1000px;
    margin: 200px auto;
    grid-gap: 10px 50px;
    grid-template-columns: 3fr 12fr 4fr 5fr;
}
.post > * {
    grid-column: 2 / -2;
}

Figure Images and Captions

The HTML structure of the figure looks like this:

<article class="post">
    ...
    <figure>
        <img src="" alt="Big Image">
        <figcaption>Super Nice Photo</figcaption>
    </figure>
    ...
</article>

We want to span the image across all columns, to do this:

  • Remove the margin
  • Position the start and stop of the grid-column to the entirety of the grid
  • Style the caption
.post > figure {
    margin: 0;
    grid-column: 1 / -1;
}
figcaption {
    font-size: 10px;
}

Styling Blockquotes

Similar to the figure images, we’ll span the blockquote to the start and end columns of the grid, and add:

  • font-size of 60px
  • font-style of italic
  • text-align it to the centre
  • Remove the margin
.post > blockquote {
    margin: 0;
    grid-column: 1 / -1;
    font-size: 60px;
    font-style: italic;
    text-align: center;
}

Finally, we’ve got these tips that will sit on either the left of right column gutters.

To style the tips, add:

  • background of #FAFAFA
  • a padding 10px
.tip {
    background: #FAFAFA;
    padding: 10px;
}

The left and right tips will have slightly different styling to suit its position.

So for the tips called with tip-left, we’ll apply the following:

  • grid-column to start on the first column and span 1 column
  • text-align to the right
  • add a border-right with a solid yellow line of 2px
.tip-left {
    grid-column: 1 / span 1;
    text-align: right;
    border-right: 2px solid var(--yellow);
}

When we move the tip to the first column, this means that the content below will shift up in line with the tip.

Similarly, we’ll apply styling to the right, but arranging it in the opposite direction.

.tip-right {
    grid-column: span 1 / -1;
    border-left: 2px solid var(--yellow);
}

One thing to note is that if the tip has beyond a certain amount of content than it’s adjacent grid item, it will stretch the row causing a massive gap in the centre column. Like so:

A way around this is to increase the number of grid-rows from a default of 1 to say 5

.tip {
    background: #FAFAFA;
    padding: 10px;
    grid-row: span 5;
}

But this will cause other tips to stretch. To stretch only to its content, we can then align-self at the start.

.tip {
    background: #FAFAFA;
    padding: 10px;
    grid-row: span 5;
    align-self: start;
}

Below is the final result, which concludes the CSS Grid Series.

Griddyup
CSS
Css Grid
Web
Web Development
Recommended from ReadMedium