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 code snippet websites for every web developer and designer

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


1️⃣ 30 Seconds of Code

- Short code snippets for all your development needs

πŸ”—
https://t.co/91L4bAxkgF


2️⃣ Free Frontend

- Free hand-picked HTML, CSS and JavaScript (jQuery, React, Vue) code examples, tutorials and articles

πŸ”— https://t.co/2sIAm73EdZ


3️⃣ Little Snippets

- A free collection of HTML and CSS code snippets

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


4️⃣ CSS Deck

- Collection of Awesome CSS and JS Creations to help out frontend developers and designers.

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

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
Do not write CSS code, use these free generators instead that can help you immensely

A Thread 🧡

1️⃣ Stripes generator

- Pure CSS Stripes Generator that you can use for backgrounds.

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


2️⃣ Gradient generator

- As a free css gradient generator tool, this website lets you create a colorful gradient background for your website, blog, or social media profile

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


3️⃣ Pattern generator

- It lets you create background pattern for free

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


4️⃣ CSS Accordion Slider Generator

- Create fully responsive, css only accordion sliders

πŸ”— https://t.co/x0qaDhN0z9
6 amazing GitHub repositories that can help you as a developer

🧡 πŸ‘‡πŸ»

1️⃣ HTML Best Practice

- This repo will help you writing maintainable and scalable HTML documents

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


2️⃣ 30 Days Of React

- Learn React in 30 days. A well divided topics of React in days. Definitely check it out

πŸ”— https://t.co/8WTc1RQOGV


3️⃣ Design resources

- Curated list of design and UI resources from stock photos, web templates, CSS frameworks, UI libraries, tools and much more

πŸ”— https://t.co/82o5Eyhlji


4️⃣ Websites a programmer should visit

- A well curated list of websites a programmer should visit

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

You May Also Like