A complete beginner's guide to CSS Grid layout πŸ‘‡πŸ»

Thread🧡

Grid is used for making complex web design layouts more easily as it's not so hard to master

Using Flex you can make only 1D layout but Grid gives you full power of creating 2D layout

Let's start

{ 2 / 21 }
First things first, start with giving the display property "grid" to the container element or parent element

{ 3 / 21 }
Nothing will change after adding display: flex; in the parent container becuase we need to define the width of columns. In order to set that columns width we have gird-template-columns property

{ 4 / 21 }
Let's start with defining the width of our columns.

For example, let's say I need two columns of width 60% and 40% respectively

grid-template-columns: 60% 40%;

{ 5 / 21 }
Ahh!! My grid items looks ugly as there is no spacing between them.
Here "grid-gap" property comes into play. For example I need 10px spacing along column and row

grid-gap: 10px;

{ 6 / 21 }
Similary we have grid-template-rows.

It is used to define the number of rows and height of rows.

grid-template-rows: 200px 400px;

{ 7 / 21 }
As you can see there is a lot of repeated code in
grid-template-columns: 200px 200px 200px 200px 200px;

Instead of this we can use repeat function πŸ‘‡πŸ»

grid-template-columns: repeat(5, 200px);

{ 8 / 21 }
You might run into some responsiveness issues if you pass pixel unit or percentage in your grid-template-columns

In order to prevent this, it is recommended to use fraction values

For example πŸ‘‡πŸ»

{ 9 / 21 }
You can use repeat function for fr as well

repeat(2, 1fr 2fr);

It wil repeat 1fr 2fr two times.

{ 10 / 21 }
Alright moving forward, you can set he height of grid element using grid-auto-rows

For ex, grid-auto-rows: 200px;

{ 11 / 21 }
Though there is a problem. By doing this, we are setting the fixed height so content inside items can be overflow.

For example πŸ‘‡πŸ»

{ 12 / 21 }
In order to prevent this kind of issues we have minmax function

grid-auto-rows: minmax(200px, auto);

It's pretty intuitive that the height of gird items will be 200px minimun and "auto" maximun(according to content)

{ 13 / 21 }
From 14 to 21

https://t.co/QcX5188vjp

More from Pratham πŸ‘¨β€πŸ’»πŸš€

I've brought you some amazing GitHub repositories of web development tips and tricks 🌟

THREADπŸ§΅πŸ”½

1️⃣ JS Tips

- A huge list of 73 great tips and tricks of JavaScript

πŸ”—
https://t.co/r0J9vW8WrH


2️⃣ CSS Protips

- A collection of tips to help take your CSS skills pro. Definitely check it out

πŸ”— https://t.co/5haB2xTWuz


3️⃣ JS Tips and Tricks

- Some advanced tips and tricks of JavaScript that can help you to take your skills onto next level

πŸ”— https://t.co/NvfoANwweV


4️⃣ Git Tips

- Git is an essential tool for very programmer. in this repo you'll find the most commonly used git tips and tricks

πŸ”— https://t.co/34qvOhYCZE
Five free VS Code extensions that will change the way you do web development:

1. RapidAPI Client

Fulfill all your need for API development.

β€’ Test and consume APIs
β€’ Work with your VS Code theme
β€’ Generate TypeScript, Swift, and Python interfaces from responses.

πŸ”—
https://t.co/FR0QhyTi8v


2. Better Comments

Create more human-friendly comments in your code.

β€’ Alerts
β€’ Queries
β€’ TODOs
β€’ Highlights

πŸ”— https://t.co/AV2BwAMAlL


3. Git Graph

View a Git Graph of your repository and efficiently perform Git actions from the graph.

πŸ”— https://t.co/S5wagmTgsa


4. Peacock

Do you have a habit of keeping multiple VS Code windows open?

Peacock lets you change the color of your VS code even if multiple instances are open.

πŸ”— https://t.co/bmidPkTQOK
12 websites that will help you learn web development faster (completely free): 🧡

1. How HTTP Works

Everything you need to know about HTTP based system.

πŸ”—
https://t.co/gVZS4RzS1a


2. 30 Days of Node

Learn Node step by step with interactive examples and code snippet in 30 days.

πŸ”— https://t.co/9nbtMiNB1C


3. How DNS Works

Learn what happens when you type a website address in your browser

πŸ”— https://t.co/SqMRNnDbc3


4. Git

Check out this excellent free website to learn git visually.

πŸ”— https://t.co/rQJMISBDfS

More from Coding

These 5 visualizers will help you learn data structures and algorithms up to 10 times faster

Thread πŸ§΅πŸ‘‡πŸ»

1⃣
https://t.co/H2sKWKEeaz

- Learn DSA and visualize some complex programs. Definitely check it out.


2️⃣ https://t.co/0WcFTWBfh9

- Dedicated to graph DS


3️⃣ https://t.co/ShEQQkjtWD

- Visualizing data structures and algorithms through animation


4️⃣ https://t.co/XxzwBa3vvZ

- All sorting algorithms animations

You May Also Like