Highlighted Blogposts

In this lesson, we will change the order of blogposts based on a feature that positions the highlighted blogpost first.

We'll cover the following

Formatting the third blogpost

Let’s make the third blogpost highlighted by adding a highlighted class to it:

<div class="blogpost highlighted">
    alt="placeholder image"
    class="blogpost-thumbnail" />
  <h3 class="blogpost-title">Third post</h3>
  <p class="blogpost-preview">This is an example post.</p>

We will use a lightskyblue background color to differentiate between the highlighted and non-highlighted color. Changing the order of the blogposts is possible above the first breakpoint because from a small screen size and above, the blogposts appear in a Flexbox.

Therefore, it is sufficient to set the order of the highlighted blogpost to -1:

.blogpost.highlighted {
    order: -1;
    background-color: lightskyblue;

We do not have this luxury for the mobile view because the layout is currently not a Flexbox. Therefore, we will have to change the block layout to Flexbox.

First, we will move the following rules from the first breakpoint to the default styles:

.blogposts {
  display: flex;
  flex-wrap: wrap;

Interestingly, this change is sufficient in itself, because the width of the Flex items is set to the full width of the container anyway.

Remember, always think about choosing the most compact and descriptive stylesheet. In this exercise, the highlighted post feature revealed an unnecessary distinction between the mobile screen size and the medium screen size, because it makes no sense to keep the display mode of the blogpost container different for the mobile screen size and the medium screen size.

The final code looks as follows:

Get hands-on with 1200+ tech skills courses.