Styling the recent posts - part 6


Styling the recent posts section for our Next portfolio

13 Oct, 2022 ยท 4 min read

Now that we have the intro header styled let's look at the rest of the homepage.

There are two sections left here: the recent posts and the featured work section.

There are some things to note here:

  • The section header is a recurring element
  • The recent posts section has a different background

With that said, let's get started on the first one.

Styling the recent posts section

Let's start by adding a new component to keep things organized. I added a recentPosts.js file in my components structure.

Let's bootstrap the main elements.

export default function RecentPosts() {
  return (
    <section className='bg-blue-100'>
      <div className='max-w-4xl mx-auto py-12'>header</div>

This will already render the blue section with a smaller container inside. We use the same max-width as we used for the intro header section.

It already looks like the image below:

Recent post section

As mentioned, the section header part is recurring, so let's make this component so we can easily re-use it.

Create the sectionHeader.js component and put the following markup inside.

export default function SectionHeader() {
  return (
      <a href='#'>View all</a>

Let's add it to our recentPosts component.

import SectionHeader from './sectionHeader';

export default function RecentPosts() {
  return (
    <section className='bg-blue-100 px-6'>
      <div className='max-w-4xl mx-auto py-12'>
        <SectionHeader />

Now head back to the section header, and we'll add the styling we need.

First of all, we need to make it a flexbox wrapper. With space between the two elements, and center them horizontally.

<div className="flex justify-between items-center MB-8"></div>

The h2 element should reflect the size of the design and be a bold type.

<h2 className="text-2xl font-bold"></h2>

And lastly, we can style the button to look neater.

<a className="text-red-400 font-bold" href="#"></a>

This will already look great. However, the components are still static. Let's ensure we can pass some data to this component.

export default function SectionHeader({ title, href }) {
  return (
    <div className='flex justify-between items-center MB-8'>
      <h2 className='text-2xl font-bold'>{title}</h2>
      <a className='text-red-400 font-bold' href={href}>
        View all

And now, when we import this component, we can pass the title and href as props.

<SectionHeader title='Recent posts' href='#' />

Section header styled

Now let's work on the articles themselves. As we can see, there are two next to each other. The easy way to achieve this is to wrap them in a grid like this:

<div className='grid grid-cols-2 gap-6'></div>

Now let's add another component we'll call article.js. For now, we will use static data so that each article will be the same.

export default function Article() {
  return (
      <h3>Post Title</h3>
        <date>12 Feb 21</date> | Design System
        Amet minim mollit non deserunt ullamco est sit aliqua dolor do amet
        sint. Velit officia consequat duis enim velit mollit. Exercitation
        veniam consequat sunt nostrud amet.

Let's start by adding some styling to the main article element.

<article className="bg-white p-4 rounded-lg"></article>

Then on to the title element.

<h3 className="text-2xl mb-2 font-medium"></h3>

And for the date and tag element.

<span className="text-gray-600 mb-4 block"></span>

Now head back to your recent post component and add two article components.

<div className='grid grid-cols-2 gap-6'>
  <Article />
  <Article />

Let's see how far we are now.

Recent posts styled

Wow, it's starting to look like the design, excellent!

You can find the code on GitHub.

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Spread the knowledge with fellow developers on Twitter
Tweet this tip
Powered by Webmentions - Learn more

Read next ๐Ÿ“–

Next portfolio - Filter by category

30 Nov, 2022 ยท 5 min read

Next portfolio - Filter by category

A glance at Turbopack

17 Nov, 2022 ยท 3 min read

A glance at Turbopack

Join 1900 devs and subscribe to my newsletter