Use CSS Grid for a magazine-style layout
You can use flexible, attractive layouts for many different types of page content. Here's how to use CSS Grid to create a magazine-style layout.
CSS offers a lot of flexibility for designing attractive and responsive layouts. A magazine-style layout organizes content that combines photos and text in an eye-catching, engaging format, making it a popular choice.
CSS Grid gives you the tools and granular control needed to achieve a magazine-style layout. So, this is a great interface design technique worth learning.
What is a magazine layout?
The magazine-style layout uses a grid structure to organize content in columns and rows. They are great for displaying different types of content like articles, photos, and ads in an attractive and organized way.
What is CSS Grid?
CSS Grid is a powerful layout tool that allows you to define elements in two dimensions, making it easy to create columns and rows.
With this type of layout, two main components come into play: the grid container, which is responsible for defining the structure of the grid, and the grid items, which are children of the container.
Here's a simple example of how you can CSS Grid to create a 3x3 grid:
.grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; } .grid-item { background-color: #f76a6a; padding: 20px; }
This code defines a grid container with 3 columns of equal width and 20px spacing between items. Result:
Set up HTML structure
For a magazine-style layout, you need a well-structured HTML document. Consider using semantic elements to organize content such as and . Here is a good starting point:

Article title

Article title

Article title

Article title

Article title
Define container grid
To create a grid for a magazine-style layout, add the following CSS code:
.magazine-layout { height: 100%; max-width: 130rem; margin: 0 auto; /* Xác định container grid */ display: grid; /* Xác định đặc điểm cột */ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); /* Xác định đặc điểm hàng */ grid-template-rows: repeat(auto-fit, minmax(250px, 1fr)); gap: 2rem; padding: 2rem; }
This CSS defines the container element, .magazine-layout , as a grid container using the display: grid declaration .
The grid-template-columns and grid-template-rows properties use a combination of repeat , auto-fit and minmax . They ensure a minimum column width and column height of 250px and that as many items as possible fit in each column.
Place items in the grid
Now style each post and its content to create attractive thumbnail-style elements:
article { overflow: hidden; border-radius: 0.5rem; position: relative; color: #fff; } .article img { width: 100%; height: 100%; object-fit: cover; display: block; max-height: 400px; } .article p { position: absolute; bottom: 0; left: 0; padding: 2rem; background: #333333c1; font-size: 2rem; border-radius: 0.5rem; }
At this point, your website will look like this:
Create a magazine-style layout
For a true magazine-style look, add CSS styles to expand the elements in the article in the order you want:
.article:nth-child(1) { grid-column: 1 / span 3; } .article:nth-child(4) { grid-column: 2 / span 2; }
Your page will look like this:
Responsive design using CSS Grid
One of the advantages of CSS Grid is its inherent responsiveness. You can use media queries to adjust the layout for different screen sizes. For example:
/* Truy vấn media cho màn hình 1100px */ @media screen and (max-width: 1100px) { .article:nth-child(3) { grid-column: 2 / span 2; } .article:nth-child(5) { grid-row: 3 / span 1; } } /* Truy vấn media cho màn hình 600px */ @media screen and (max-width: 600px) { .article:nth-child(2), .article:nth-child(3), .article:nth-child(4), .article:nth-child(5) { grid-column: 1 / span 3; } }
These media queries convert between multiple layout definitions to best fit the device's screen size. The final layout will adapt to different sizes.
CSS Grid is a flexible tool that you can use to create magazine-style layouts that work for a variety of screens. It allows you to define grid structures, place items, and adjust layouts.
Experiment with different grid configurations and styles to achieve the perfect magazine layout for your website.
You should read it
- Inviting GRID 2 racing game worth $ 29.99, is free
- How to turn the photo into a more artistic minimalist style
- How to Create a Magazine on Flipboard on Android
- Download GRID Autosport racing game worth $ 39.99, free of charge
- How to Create a Magazine on Flipboard on PC or Mac
- How to Increase the Popularity of Your Flipboard Magazine
- How to create custom grid systems in Photoshop
- Google Meet Grid View - Get Google Meet Grid View here
May be interested
- How to Increase the Popularity of Your Flipboard Magazineflipboard not only allows you to read and enjoy various articles and contents available on the internet, but also lets you collect those writings that you like and piece it all together to make your very own magazine. so what's next after...
- Layout in HTMLwebsites often display content in the form of columns (like in newspapers or magazines).
- How to arrange 5.1 speakers for perfect sound qualityto own a 5.1 speaker system with the best emitting sound, in addition to properly assembling speakers, special attention must be paid to the arrangement of the system so as to maximize the performance quality and harmony with space. the 5.1 layout tips below will help users to get the perfect, perfect theater-like sound space, while also demonstrating the host's style and personality.
- How to create custom grid systems in Photoshopin this post, tipsmake.com will show you how to create custom grids for both css and photoshop. to make this process easy, the article will use several tools.
- How to use Windows 11's Snap Layout on Windows 10snap layout is one of the standout features of windows 11. when you have a bunch of windows open across different apps, windows 11 lets you arrange them all on the screen based on different layouts, then that are saved in a particular arrangement.
- Google Meet Grid View - Get Google Meet Grid View herea free chrome extension called google meet grid view lets you see everyone in a meeting, no matter how many people there are.
- What is the operating style of Steve Jobs and Tim Cook different?according to the memoir of walter isaacson - cnn president and editor of time magazine, steve jobs is an outstanding, determined, determined and temperate person. meanwhile, tim cook is evaluated as very different, maintaining the principles, principles and quite convincing.
- America must prepare 'carefully' for the Japanese Food Festival which will take place on August 21the solar eclipse of august 21 will affect the us solar grid
- How to Play Sunderfolk: Useful Tips for Beginnerssunderfolk is a fun turn-based tactical rpg and tabletop style game where you and your friends fight together on a grid filled with enemies.
- Facebook updates the new interface, adding a grid view on the personal pagesocial network facebook version on the web browser has recently been updated with the new interface, allowing users to have a new option of a grid format outside the list of currently used lists.