Polishing Layout
So far, we’ve only added minimal React and CSS code just to illustrate concepts such as CSS Modules. Before we move on to our next lesson about data fetching, let’s polish our page styling and code.
Update components/layout.module.css
First, open components/layout.module.css
and replace its content with the following more polished styles for the layout and profile picture:
Create styles/utils.module.css
Second, let’s create a set of CSS utility classes (for text styles) that can be re-used across multiple components.
Add a new CSS file called styles/utils.module.css
with the following content:
You can reuse these utility classes throughout your application, and you may even use utility classes in your
global.css
file. Utility classes refer to an approach of writing CSS selectors rather than a method (e.g. global styles, CSS modules, Sass, etc). Learn more about utility-first CSS.
Update components/layout.js
Third, open components/layout.js
and replace its content with the following code, changing Your Name
to an actual name:
Here’s what’s new:
meta
tags (likeog:image
), which are used to describe a page's content- Boolean
home
prop which will adjust the size of the title and the image - "Back to home" link at the bottom if
home
isfalse
- Added images with
next/image
, which are preloaded with the priority attribute
Update pages/index.js
Finally, let's update the homepage.
Open pages/index.js
and replace its content with:
Then replace [Your Self Introduction]
with your self-introduction. Here’s an example with the author’s profile:
That’s it! We now have the polished layout code and we're ready to move on to our data fetching lessons.
Before we wrap up this lesson, let’s talk about some helpful techniques related to Next.js’s CSS support on the next page.