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 ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿš€

5 great background websites for every web developer and designer

๐Ÿงต๐Ÿ‘‡


1. Magic pattern

Beautiful pure CSS background patterns that you can actually use in your projects. They are highly customizable as well.

๐Ÿ–‡๏ธ
https://t.co/ZqczrPfkdZ


2. Cool backgrounds

Collection of cool backgrounds that you can add to blogs, websites, or as desktop and phone wallpapers

๐Ÿ–‡๏ธ https://t.co/df7VSb9t8H


3. Gradienta

Use pure CSS gradient backgrounds for your next website or app, as a JPG image or CSS code, no attribute required

๐Ÿ–‡๏ธ https://t.co/R58zrwpZCH


4 Mesh gradient

Creat aurora UI like gradients using few simple clicks

๐Ÿ–‡๏ธ https://t.co/vOHHDASr1V
If you know CSS then you can use these amazing generators and save your time

Thread ๐Ÿงต๐Ÿ‘‡๐Ÿป

1๏ธโƒฃ CSS Box Shadow Generator

- Generate CSS3 Box Shadow code for your Div, Frame, Buttons or any other HTML element with Outline, and Inset (inner) type shadow effects

๐Ÿ”—
https://t.co/6La36IzBLj


2๏ธโƒฃ Glassmorphism

- Generate glassmorphic design easily

๐Ÿ”— https://t.co/qrKqDV5tzY


3๏ธโƒฃ Cool Backgrounds

- Explore a beautifully curated selection of cool backgrounds that you can add to your next project

๐Ÿ”— https://t.co/df7VSaRSh9


4๏ธโƒฃ Pixel art

- Create CSS pixel art, export the results to CSS and download them.

๐Ÿ”— https://t.co/ojD8qwzuhx
5 amazing GitHub repositories for every self taught developer

A Thread ๐Ÿงต

1๏ธโƒฃ Computer Science

๐ŸŽ“ Path to a free self-taught education in Computer Science!

๐Ÿ”—
https://t.co/67jB5zqIes


2๏ธโƒฃ Free Certifications

Curated list of free courses & certifications

๐Ÿ”— https://t.co/4XtlAVlovs


3๏ธโƒฃ Free Programming Books

๐Ÿ“š Freely available programming books

๐Ÿ”— https://t.co/eOWLCtwtIV


4๏ธโƒฃ JavaScript Question

A long list of (advanced) JavaScript questions, and their explanations โœจ

๐Ÿ”— https://t.co/UvEl1Esvh3

More from Coding

5 amazing websites that will blow the mind of a developer. Definitely check them out

๐Ÿงต๐Ÿ‘‡๐Ÿป

1๏ธโƒฃ Animation generator

- Dead simple visual tools to help you generate CSS for your projects.

๐Ÿ”—
https://t.co/IFmIEgDiVY


2๏ธโƒฃ Neural Network Visualizer

- Deep playground is an interactive visualization of neural networks, written in TypeScript using d3.js.

๐Ÿ”— https://t.co/mTAlFbJsOW


3๏ธโƒฃ Blockchain Demo

- A visual demo of blockchain technology

๐Ÿ”— https://t.co/I1RwxYcM1Z


4๏ธโƒฃ Developer Roadmaps

- Step by step guides and paths to learn different tools or technologies

๐Ÿ”— https://t.co/VSNPdG8jQR

You May Also Like