Styling the recent posts - part 6

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Now that we have the recent post section let's look at the last bit of the homepage. This will be the featured work section. The design shows us the following element. We can see some outlined items here: The section header we created yesterday Wor...
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

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:
With that said, let's get started on the first one.
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>
</section>
);
}
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:

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 (
<div>
<h2>Title</h2>
<a href='#'>View all</a>
</div>
);
}
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 />
</div>
</section>
);
}
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
</a>
</div>
);
}
And now, when we import this component, we can pass the title and href as props.
<SectionHeader title='Recent posts' href='#' />

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 (
<article>
<h3>Post Title</h3>
<span>
<date>12 Feb 21</date> | Design System
</span>
<p>
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.
</p>
</article>
);
}
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 />
</div>
Let's see how far we are now.

Wow, it's starting to look like the design, excellent!
You can find the code on GitHub.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter