Positioning in CSS allows you to display your element wherever you want on the screen

But when I was learning it, I found it little bit confusing๐Ÿ˜…

So in this thread I'll try to explain it in easiest manner with practical implementation. Let's start

THREAD๐Ÿงต๐Ÿ‘‡
There are 5 values that you can pass in position property

- static
- relative
- absolute
- fixed
- sticky

In this thread we will be focusing on relative and absolute positioning as both are widely used
Let's start with understanding what document flow is?

๐Ÿ“Œ Elements are displayed on the screen as they written in the HTML document

Consider the following piece of code:

H1, P, H3 and div are displayed on the screen in exact order as they written in the HTML file.
As now you know about document flow, let's start with Relative positioning

๐Ÿ“Œ Relative Position

- Relative positioning do not take an element out of document flow
- Relative positioning is relative to element's original position which can be changed using offset
๐Ÿ”น Relative position is relative to itself.

For example: Consider the code and output in the attached image below

As you can see red box is shifted 100px from left because I applied left offset after giving it relative positioning
In the attached image below, the black dotted area would be the original position of red box if I don't apply position relative in it.

As you can see it proved that relative position is relative to itself
So now let me shift the blue box 100px towards left. So how can I do that? it's simple

.blue {
position: relative;
right: 100px;
}

Notice here that document flow is as it is. So the relative position does not affect the document flow
๐Ÿ“Œ Absolute Position

- The element is removed from the normal document flow
- You can consider it as, after applying absolute position the element will no longer in the flow and no space is created for the element in the page layout
For example:

If I apply absolute position in the red box, then the red box will be out of the flow and hence no space will be allocated to it.

See the image below, red box is out of flow and hence yellow box is at top and followed by green and blue

* Yellow box is below red
- The absolute position of an element is relative to its closest ancestor, which has some position property.

Consider the code below, Red is the parent div and black is the child div. In this particular case, body is the parent of red div
Now let me apply relative position to red(parent) div and absolute position to black(child) div.

As I mentioned absolute position is relative to closest ancestor having some position property
Let's understand it in little more details๐Ÿ‘‡

Consider this piece of code.

Here green div is a parent of red and red div is a parent of black
So let me apply position property in green and black. In black div we have absolute position so in that case black div will be relative to green not red

Because here black's closest ancestor is green which has some position property
I think that's pretty much it for this thread. I hope you get a overview of CSS positioning

This may sound a bit confusing but try to play with code. You'll be able to build better understanding๐Ÿ˜„

Feel free to post your doubts belowโค๏ธ

โ€ข โ€ข โ€ข

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

29 Jan
Everything you need to know about useState hook of React

A beginner's guide

Thread๐Ÿงต๐Ÿ‘‡ Image
Hey๐Ÿ‘‹

Hooks are powerful but confusing. Don't worry, I'll try to explain each hook in the easiest way in this thread series of React hooks

Let's start with useState, the most useful and simple hook in my opinion
Working with React hooks, first thing you need to do is to import the particular hook

It's quite easy๐Ÿ‘‡

๐Ÿ“Œ import { useState } from "react";
Read 14 tweets
27 Jan
Complete Beginner's guide to React in 2021โš›๏ธ

A Long Thread๐Ÿงต
If you just started or planning to getting started with React, this thread might help you.

In this thread I'll try to give you a quick overview to the world of React.

So if you find that sound interesting, prepare a coffee and give this thread a read๐Ÿ˜‰
Before you go further into the React, make sure to check these things

โœ… Basic knowledge of HTML and CSS
โœ… JavaScript fundamentals and ES6 features

I would like to suggest you build a decent hold on JavaScript concepts because that is the backbone of React
Read 35 tweets
26 Jan
50 Resources for learning React in 2021โš›๏ธ

Thread๐Ÿงต๐Ÿ‘‡
๐Ÿ“Œ DOCUMENTATION

1. React official docs
reactjs.org/docs/getting-sโ€ฆ

2. MDN docs
developer.mozilla.org/en-US/docs/Leaโ€ฆ

3. W3 Schools
w3schools.com/react/
Read 18 tweets
24 Jan
63 RESOURCES OF CSS๐ŸŒˆ๐Ÿ‘‡

Thread๐Ÿงต
๐Ÿ“Œ COLORS

1. Color Hunt
colorhunt.co

2. Coolors
coolors.co

3. HTML color codes
htmlcolorcodes.com

4. UI Gradients
uigradients.com/#Bupe

5. Gradient generator
cssgradient.io
6. Encycolorpedia
encycolorpedia.com

7. WebFx
webfx.com/web-design/colโ€ฆ

8. Radial Gradient
css-gradient.com

9. COLORS
clrs.cc

10. Flat UI colors 2
flatuicolors.com
Read 14 tweets
23 Jan
Let's create this LOADING animation in less than 15 minutes๐ŸŒˆ

THREAD๐Ÿงต
The HTML structure is pretty straight forward

- Create a container div

- Create 7 different span elements for each letter in the word "LOADING"
- Centralize everything, I have used positioning in order to center my elements but you can use any method you want
Read 8 tweets
23 Jan
50 resources for learning JavaScript in 2021๐Ÿ‘‡

Thread๐Ÿงต
In this tweet you will find resources in various form

- Documentation
- Courses
- Websites
- YouTube Videos
- Books
- GitHub Repos
- Interactive learning
- Projects
๐Ÿ“Œ DOCUMENTATION

1. MDN
developer.mozilla.org/en-US/docs/Webโ€ฆ

2. W3 Schools
w3schools.com/js/

3. DevDocs
devdocs.io/javascript/

4. JavaScript Info
javascript.info

5. JavaScript Garden
bonsaiden.github.io/JavaScript-Garโ€ฆ
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!