How Positioning works in CSS 🧐

β—Ό static
β—Ό relative
β—Ό absolute
β—Ό fixed
β—Ό sticky

Thread 🧡
Positioning is one of the core concepts of CSS.

It isn’t as easy as it seems.

I think you must have encountered certain things like navbar or sidebar.

We scroll the webpage but they don't move from their position.
πŸ“Œ What is Positioning?

Positioning in CSS means, to set the position of an element in the webpage.

The property used in positioning is CSS position.
The top, right, bottom, and left properties don't work without specifying the position property.

These properties are used to set the final position of an element.
Position property takes several values such as

β—Ό static
β—Ό relative
β—Ό absolute
β—Ό fixed
β—Ό sticky

Let's explore each value πŸ‘‡
1️⃣ static:-

You don't have to specify static value because it's a default value of an Element.

top, right, bottom, and left properties do not work with this.

And The element is positioned according to the normal flow of the document.
2️⃣ relative:-

Element with relative position remains in the normal flow of the document.

But the top, bottom, left, right properties work with this and affect the element position.

These all properties work relative to the element itself.
Notice the second element moves 200px into the left relative to itself,

But doesn’t affect other elements’ positions.
3️⃣ absolute:-

An element with an absolute value breaks out from the normal document flow.

So it affects other elements as well because it breaks out from the normal flow,
which means other elements think it is not in the document.

And the element gap is filled by other elements.

top, bottom, left, right properties work with this and affect the element position.
keynote is that an element with absolute position is positioned relative to its closest positioned ancestor.

it looks up for relative parent if any of its ancestors are not relative then it becomes relative to <html>.
4️⃣ fixed:-

fixed-position elements are also removed from document normal flow like absolute elements.

the key difference is they are relative to <html> and fixed elements are not affected by scrolling.

top, bottom, left, right properties work with this.
5️⃣ sticky:-

position sticky is a mix of position relative and position fixed.

it behaves like a relative element until it hit specified points via top, bottom, left, and right properties.
it acts like relative until it hits the point top:50px and then it acts like a fixed element.
I hope you understood how position property works.
Thanks for stopping and checking these resources,

I'm sure it's going to help you at some point in time.

βœ… Follow @Ali6nX404 for more such content.

β€’ β€’ β€’

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

Keep Current with Mahesh πŸ‘½πŸ›Έ

Mahesh πŸ‘½πŸ›Έ 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 @Ali6nX404

9 Jan
If you don't know "How CSS Works",

because of this sometimes it feels like Black Magic πŸͺ„

That's why I'm constantly creating content to simplify complex CSS topics. 🀞

Here is my top creation of 2022 πŸ‘‡πŸ§΅
2️⃣ min/max width and height

Read 7 tweets
8 Dec 21
π˜Ύπ™Žπ™Ž π™Žπ™šπ™‘π™šπ™˜π™©π™€π™§π™¨ 𝙂π™ͺπ™žπ™™π™š βœ…πŸ’™

βœ” Universal Selector
βœ” Class selector
βœ” Type selector
βœ” ID selector
βœ” Attribute selector

Many More...

π“π‘π«πžπšπ 🧡
π™ƒπ™šπ™‘π™‘π™€ π™—π™šπ™–π™ͺπ™©π™žπ™›π™ͺ𝙑 𝙃π™ͺ𝙒𝙖𝙣𝙨 πŸ‘‹

In this thread, we are going to cover basic CSS selectors with code examples.

Let's start πŸš€
πŸ“Œ What is CSS Selector?

CSS selector actually selects the content you want to style.

CSS provides different kinds of selectors to do this.
Read 16 tweets
5 Dec 21
I wasted 2 months in tutorial hellπŸ˜–πŸ˜«

But WTF is Tutorial Hell? πŸ€·β€β™€οΈ

How to escape it?πŸ™„

Thread πŸ§΅πŸ‘‡
As I started learning to code, I was stuck in tutorial hell. It felt like, I am learning a lot of the stuff.

I have mastered CSS and JS.
After Creating a lot of projects while watching tutorials.

One day I decided to create a project of my own.
Read 21 tweets
4 Dec 21
When you read CSS code and find some weird code like :

-webkit-,
-moz-,
-o-,
-ms-

Let's understand about themβš‘πŸ‘‡
What we're going to cover:-

β—Ό What is the vendor prefix.
β—Ό Prefixes used by major browsers
β—Ό Why we Use?
β—Ό property supported by browsers or not
β—Ό How we can use vendor prefixes?
β—Ό automate the vendor prefix writing
πŸ“Œ What is the vendor prefix?

CSS properties starting with -webkit-, -moz-, -ms- or -o- are called vendor prefixes.

These are the vendor-prefixed offered by the relevant rendering engines.
Read 13 tweets
3 Dec 21
Level up your CSS With These Generators and tools✨

threadπŸ§΅πŸ‘‡ Image
1️⃣ This is the best generator to design your next project grid layout visually.

Copy the CSS code directly.
grid.layoutit.com
2️⃣ This Generator allows you to create complex shapes easily.

bennettfeely.com/clippy/
Read 11 tweets
2 Dec 21
CSS resources that always save my life πŸ˜…πŸš€

Thread πŸ‘‡
This thread is just a collection of resources that I use in my day-to-day work.

πŸ‘‡πŸ˜‰
1️⃣ CSS Tricks -

CSS tricks provide so much value through articles

And whenever I need to read about something deeply I prefer CSS tricks articles.

css-tricks.com
Read 10 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

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(