Blog post Box Layouting
In this layout, we will update the layout of each blog post using Flexbox.
We'll cover the following
Blog post thumbnail, title, and summary
Each blog post will receive identical content.
We will use an online placeholder service to generate placeholder images for the thumbnails. We will use the link /udata/WPVy7kaW8e6/720x480.png
to generate an image.
Each blog post will have a thumbnail, an h3
heading, and one paragraph. These items will be displayed below each other.
<div class="blogpost">
<img
src="/udata/WPVy7kaW8e6/720x480.png"
alt="placeholder image"
class="blogpost-thumbnail" />
<h3>First post</h3>
<p>This is an example post.</p>
</div>
Technically, we could use Flexbox with flex-direction: column;
to position the Flex items below each other. However, similar to the main banner, this makes little sense, as block-level elements are already positioned below each other, and we can freely set their margins.
Therefore, this lesson gives you another example, where using Flexbox is suboptimal.
To style the blog post, let’s add a 20px
padding inside the container, around the thumbnail, the title, and the paragraph. This does not change the dimensions of the blog post, because of the global border-box
setting for all elements.
We also have to set the thumbnail image’s width to stay proportionally sized inside the Flexbox container by adding a width: 100%
rule. We can also set a 10px
vertical margin around the title and the paragraph.
.blogpost {
min-height: 100px;
border: 1px solid black;
padding: 20px;
}
.blogpost-thumbnail {
width: 100%;
}
.blogpost-title, .blogpost-preview {
margin: 10px 0;
}
We are done with the blog post styling:
Get hands-on with 1400+ tech skills courses.