A quick 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 / 17 }
First things first, start with giving the display property "grid" to the container element or parent element

{ 3 / 17 }
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 / 17 }
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 / 17 }
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 / 17 }
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 / 17 }
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 / 17 }
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 / 17 }
You can use repeat function for fr as well

repeat(2, 1fr 2fr);

It wil repeat 1fr 2fr two times.

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

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

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

For example πŸ‘‡πŸ»

{ 12 / 17 }
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 / 17 }
Well all that we have covered so far we can do that using flexbox also.

Let's understand the 2 dimensions of grid layout

{ 14 / 17 }
We can change the position of a particular items in accordance of row and column

For example, I want my first item taking up entire row, that is from first column to last column

grid-column: 1 / 4;

{ 15 / 17 }
Try to play around with code here. This migt be little confusing in the beginning but once you get used to, it all becomes pretty easy

{ 16 / 17 }

codepen.io/prathamkumar/p…
I have not covered alignment concept in this thread, will make a separate thread on it.

I think that was pretty much it, If you like this thread share it with your connections ❀️

{ 17 / 17 }
Glad to see a huge response❀️
I hope you learned something from this

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Pratham πŸ‘¨β€πŸ’»πŸš€

Pratham πŸ‘¨β€πŸ’»πŸš€ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Prathkum

1 Mar
A quick start guide to CSS animations πŸ‘‡πŸ»

Thread 🧡 Image
Animations on your web pages or website can catch more audience

You can create some amazing animation using CSS itself. In this thread, we will try to learn some decent knowledge about it

Let's start πŸ‘‡πŸ»

{ 2 / 19 }
Animation is all about changing one style to another at certain intervals or times

For doing that, first and foremost thing which we need to learn is @ keyframes at rule

{ 3 / 19 }
Read 19 tweets
28 Feb
useReducer Hook - an alternative to useState Image
useReducer is preferable to useState when you have some complex state.

It accepts three parameter out of which two are mandatory I guess

The first one is reducer function and second one is initial state
useReducer returns two things

- The first one in current state
- The second one is a dispatch function using which you can change your current state by passing action type is dispatch.
Read 4 tweets
28 Feb
I have covered some important CSS topics in my thread in last couple of days.

Here is a quick sneak peek 🧡
πŸ“Œ Relative and Absolute positioning

Read 16 tweets
26 Feb
Some general tips for writing an effective tweet or thread

🧡 πŸ‘‡πŸΌ
1️⃣ Write about the things you are good at

I always try to write tweets related to web technologies. More specifiy I try to cover CSS, JavaScript and React. By writing about the stuff that you're good, you can share huge amount of knowledge from your tweet

{ 2 / 10 }
2️⃣ Support your point with an example

If you're writing about some coding tips or tricks, It would be great if you give a example in the form of image, video, gif or link

{ 3 / 10 }
Read 10 tweets
25 Feb
Web development resources for free

Mega Thread 🧡 πŸ‘‡πŸ»
1️⃣ Online learning platforms πŸ“˜

- Udemy
- FreeCodeCamp
- Treehouse
- Frontend masters
- Coursera
- Traversy media
- SoloLearn
- Codecademy
- Udacity
- Alison
- Code college
- LinkedIn Learning
- Skillshare
- EdX
2️⃣ Editors and share code snippets ✍🏻

- PlayCode
- JSFiddle
- CodePen
- StackBlitz
- JSBin
- Codesandbox
- Codeinterview .io
- godbolt .org
- wandbox .org
- carbon .now.sh
- pastebin .com
- ideone .com
- ide .judge0.com
Read 24 tweets
25 Feb
Mastering JavaScript is a life long process but at least you can learn some basic concepts in few days to make functional web pages

Let's see howπŸ‘‡

THREAD🧡
Alright great! You're in this thread that's mean you're interestedπŸ”₯

First things first, whenever I'm up to learning new technology or language, I always start with a crash course. By doing so I get a quick overview of things in almost not time

{ 2 / 15 }
Here's a crash course of JavaScript by Freecodecamp.

Crash courses are just for quick look. Don't just stop learning after it. Keep exploring things by your own



{ 3 / 15 }
Read 15 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!