Tuesday, 5 May 2020

Build Your Own Blog - Page Layout and Flexbox

<< Creating the BlogArchive Component                                  Table of Contents

In this part of the 'Build Your Own Blog' series, we want our web page to be suitable for various screen sizes, such as mobile and laptop.

(If you're new here, I recommend visiting the Table of Contents or here for the previous post)

Flexbox is a Responsive Web Design CSS technology that allows us to dynamically alter our web page to suit the dimnesions of the screen it is being displayed in.

By the end of this post, our blog site will be capable of supporting the following screen types:

Laptop



Mobile



Notice that the Blog Archive component is being pushed to beneath the Blog Post.


1. Open app.component.sass and add the following:
























The container class is our main container class that belongs to the parent div. It adds a margin to the whole page which is proportionate to the width of the screen. This will centre our web page by bringing its components together rather than being spread out. It's easier on the eyes.

You'll notice that the blog-body class uses display: flex. This will enable Flexbox on this div and all its child items.

justify-content: space-between will spread the components across the full width of it's container whilst adding an even amount of space between them.

flex-direction: row will force our components to appear in a row instead of being in a column.

flex-wrap: wrap is the magick for pushing the BlogArchive component beneath the BlogPost component if it can no longer fit within the width dimensions of the container.


flex will dynamically size the component proportionate to other components. blog-post has flex:3 and blog-archive has flex:1 - this means BlogArchive will be 3x bigger than the BlogPost component.

flex-grow will determine how quickly the component will grow/shrink into the remaining space of the screen as the screen size changes.

2.  Open app.component.html and add the following:



The final piece in the puzzle! We use all three components that we've created in this series and we place them within their own divs and corresponding classes to apply the final layout of the page.

3. Run ng serve
Congratulation! If you've made it this far, you should now have a basic blog web site that is responsive.

In the following posts, we will dive into creating our API layer using .Net Core Web API and AWS DynamoDB for accessing our blog data.


<< Creating the BlogArchive Component                                  Table of Contents

No comments:

Post a Comment