Pratham Profile picture
25 Jun, 28 tweets, 10 min read
Next 27 tweets are the Complete Introduction to CSS Grid Layouts including everything

πŸ§΅πŸ‘‡πŸ»
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 the full power of creating a 2D layout

Let's start

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

{ 03 / 28 }
Nothing will change after adding display: flex; in the parent container because we need to define the width of columns. In order to set that column's width we have gird-template-columns property.

{ 04 / 28 }
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%;

{ 05 / 28 }
Ahh!! My grid items look 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;

{ 06 / 28 }
Similarly we have grid-template-rows.

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

grid-template-rows: 200px 400px;

{ 07 / 28 }
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 the repeat function πŸ‘‡πŸ»

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

{ 08 / 28 }
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:

{ 09 / 28 }
You can use repeat function for fr as well

repeat(2, 1fr 2fr);

It will repeat 1fr 2fr two times.

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

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

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

For example:

{ 12 / 28 }
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 minimum and "auto" maximum(according to content)

{ 13 / 28 }
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 / 28 }
We can change the position of a particular item in accordance of row and column

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

grid-column: 1 / 4;

{ 15 / 28 }
Alright moving forward, The next property we have is `grid-template-areas` which specifies the areas within the grid layout.

Each row is defined by apostrophes (' ')

Sounds confusing? Let see this in action

{ 16 / 28 }
Let's breakdown this code

grid-template-areas: 'areaName areaName areaName areaName areaName';

- Each row is defined by apostrophes (' ')
- Hence only one row in this case as there is only one pair of apostrophes
- Five "areaName" hence five columns

CONT...

{ 17 / 28 }
Now let's apply this area (areaName) to the first grid item

.one {
grid-area: areaName;
}

As you can see item1 takes one entire row and 5 columns. As simple as that

codepen.io/prathkum/pen/L…

{ 18 / 28 }
Alright, moving further let's talk about in the context of Grid items.

We can set the ordering and alignment of a particular item. Let's dive into it

{ 19 / 28 }
πŸ“Œ The Order of the items

The order is nothing but used to set the order of an item within the grid container

{ 20 / 28 }
Here is the visual example, by default the correct order should be 1 2 3 4 but I have applied order property to change the actual ordering.

{ 21 / 28 }
πŸ“Œ Alignment in CSS Grid Layout

This is a little confusing thing but we will cover everything in this thread.

justify-content
align-items
justify-self
align-self

{ 22 / 28 }
The `justify-content` is used to align the container's items when the items do not use all available space on the main-axis (horizontally).

πŸ”— w3schools.com/cssref/playit.…

{ 23 / 28 }
The `align-items` property specifies the default alignment for items inside the flexible container.

πŸ”— w3schools.com/cssref/playit.…

{ 24 / 28 }
We can use justify-self and align-self in order to set the alignment of a particular item with the grid container

{ 25 / 28 }
Let's tackle the trickiest part:

How to center horizontally and vertically using one line of CSS?

It's simple using only one line of code

place-content: center;

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

codepen.io/prathkum/pen/Y…

{ 27 / 28 }
I think that was pretty much it, If you like this thread share it with your connections ❀️

Peace out πŸ˜‰

{ 28 / 28 }

* β±α΅α΅–Κ³α΅’α΅›α΅‰α΅ˆ ᡛᡉʳ˒ⁱᡒⁿ α΅’αΆ  α΅–Κ³α΅‰α΅›β±α΅’α΅˜Λ’ α΅—Κ°Κ³α΅‰α΅ƒα΅ˆ

β€’ β€’ β€’

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

25 Jun
Cool things you can do with CSS only

🧡 πŸ‘‡πŸ»
Text portrait

πŸ”— codepen.io/prathkum/pen/x…
Texture portrait

πŸ”— codesandbox.io/s/texture-port…
Read 5 tweets
23 Jun
I have created enormous handmade notes for Web development beginners.

Here are some of my handmade JavaScript and CSS notes/cheat sheets that can help you 🧡 πŸ‘‡πŸ»
0. Semantic HTML
2. CSS border-radius
Read 13 tweets
23 Jun
Let's talk about some CSS concepts that we rarely used but they will prove that CSS is so deep.

πŸ§΅πŸ‘‡πŸ»
1. Select grammatical errors

::grammar-error pseudo-element select a grammatically incorrect sentence. Although this feature has not been standardized yet.

πŸ”— developer.mozilla.org/en-US/docs/Web…
2. You can optimize the performance of your web page by adding one line of CSS

The `will-change` property

- will-change tells the browser that how an element is expected to change
- Increase the responsiveness
Read 7 tweets
23 Jun
I again brought 5 awesome GitHub repositories for beginners

πŸ§΅πŸ‘‡πŸ»
1. Project-based learning

A curated list of project-based tutorials covering JavaScript, Python and many other popular languages

πŸ”— github.com/tuvtran/projec…
2. Awesome Linux software

A list of awesome applications, software, tools, and other materials for Linux distros

πŸ”— github.com/luong-komorebi…
Read 6 tweets
22 Jun
Are you planning to create your first CSS art for fun? Start with the basic shapes.

Here are 26 easy to hard shapes and figures you can try first πŸ§΅πŸ‘‡πŸ»
In general, analyze any image and try to think how can you make it using different shapes.

Two concepts that you need to master

1. border-radius
2. linear-gradient
1. Circle Yellow πŸ”΅

- Pretty simple, we just need to make a square and apply the border-radius 50% in order to give it a circular shape
Read 28 tweets
22 Jun
Planning to learn React? Knowledge of a few JavaScript concepts can make the process easier for you.

Let's see some basic JavaScript modules that can help you πŸ§΅πŸ‘‡πŸ»
Keep JavaScript aside for a moment, Knowledge of basic HTML and CSS is a must in my opinion.

React is all about building user interface so you'll be working with HTML and CSS as well. So start with these first
1. Basic programming knowledge which is must

- Data types in JavaScript
- Variables
- Statements
- Control statements
- Operators
Read 13 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!

:(