CSS box model is fucking hard

here's a brief explanation for dummies like me:

A thread🧵

#100Devs 💪
WTF is CSS box model?

basically, just a term to talk about design and layout.

everything on a webpage is a fucking box.

the CSS box model is a box around every HTML element. it consists of the actual content, padding, border, and margin.
from the inside out, the order of the box property is content, padding, border, and margin.

on the image below:
- the actual content is highlighted in blue
- padding is light green
- border is highlighted the darkest color
- margin is orange
there's two types of box models, standard and alternative box model

standard box model: when height and width are specified, it only applies to the CONTENT ITSELF

values of padding and border are not included, their values are added on top of the specified height and width

👇
in this example, the height and width only apply to the CONTENT inside of the <div>

we have an additional 30px padding and 5px borders on all 4 sides.

this means that the height and width is 270px (30px + 30px + 5px + 5px), not 200px because padding and border are added
this is very inconvenient because you gotta calculate the total size of the box by adding paddings & border shit

this is why we came out with the alternative box model, it fixes this issue. you don't gotta calculate shit anymore😂

👇
alternative box model: when height and width are specified, it applies to the content, padding, and border

basically, the size of the whole box is the specified width and height, INCLUDING padding and border

you achieve this by adding `box-sizing: border-box;` to your CSS

👇
the example below shows the exact same code as before, except that we added `box-sizing: border-box;`

since the box's size is the specified height and width, the size of the actual content shrinks in order to fit the padding and border within the specified height and width.
`box-sizing: border-box;` made the whole <div> height and width 200px

this means the the height and width size of the actual CONTENT is 130px (200px - 30px - 30px - 5px - 5px)

basically, whole size of the box, minus padding on both sides, minus border on both sides
this is different for margins though...

you would think that when you have 2 elements side by side, each with specified margins, they would add up just like padding and border...creating a very large margin

but this is not true.
margins collapse to one, forming a single margin between both elements

CSS chooses the margin with the larger value out of the two.

on the example below, `.box2` wins. there's a 40px margin between both boxes, not 60px
when to use margin or padding?

use MARGIN to create space between 2 ELEMENTS

use PADDING to create more space between the CONTENTS of an element and its BORDER
that's it for today! thank you so much for making it through this long ass post😆

today i re-learned the CSS box model, so i thought making this thread would be good practice/active recall to solidify my knowledge

check me out to follow my journey!!❤️ @codingyuri

• • •

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

Keep Current with yuri lee 🇰🇷

yuri lee 🇰🇷 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 @codingyuri

Jan 2
I’ve seen people sell Web3/blockchain courses at a ridiculous price💀

so here are some FREE & GOOD resources to learn web3👇
don’t let your FOMO spend thousands on a course when there’s so many excellent free alternatives

the Web3 space is still so new that there isn’t guarantee of anything yet...it isn’t realistic to be job ready after a 3 week course that cost you thousands😅

Here are my favorites:
1. blockchain.berkeley.edu/courses/

Blockchain at Berkeley gives a great introduction to cryptocurrency and the blockchain.

IMO, it’s great for beginners who don’t know shit, as it helped me have a grasp of what the hell all of this is.

It really painted the whole picture for me!
Read 6 tweets
Dec 21, 2021
WTF is crypto and blockchain??

Explained from the very start (for the real fucking beginners) 😆

A thread 🧵
With Web3 trending, there's a lot of people trying to get into the crypto and blockchain space.

There's plenty of resources for 'beginners', but as a person with NO technical background at all, most of it seems like technical jargon...what if you don't know any of that shit?😂
Friendly reminder that I'm still learning!

Feel free to correct me if I'm wrong and give me any advice, be nice though lol😂

Also, I'm hosting Web3 and blockchain conversations/threads on the Ponder app, so join me if you're interested!!

getponder.com
Read 24 tweets
Oct 14, 2021
How improving your writing skills helps advancing your tech career

A thread 🧵
Writing isn't really a skill that aspiring devs think that'll help their careers.

Most of us spend all of our time learning new languages and frameworks, but improving your writing skills advances your tech career and helps you standout in the tech industry as well!
In this thread, we'll mostly talk about the benefits of technical writing, & a few tips on how to become a better writer.

Benefits ✅
-Writing === Learning
-Networking
-Problem solving
-Team communication
-User empathy
-New career opportunities

Tips:
-Get to the point
-Clarity
Read 26 tweets
Oct 3, 2021
5 tips for web dev newbies
My advice.

A thread 🧵
1️⃣ ONLY COMPARE YOURSELF TO YESTERDAY'S YOU

As long as you learned something new today, you've made progress.

It can be a single word, concept, whatever small it may be, as long as you know something today you didn't know yesterday, you're making progress✨💘

👇
This is THE secret to a healthy mindset, don't be too hard on yourself. Learning something new in itself is already fucking hard!!!

Everyone takes their own time and has their own way of understanding things. Your journey is YOURS alone.
Read 10 tweets
Sep 29, 2021
WTF is Web 3.0?

A thread🧵
Y'all ready to fill your brains with juicy ass info?!🔥

Quick table of contents:
- What is Web3?
- Problems with Web2
- How Web3 solves the problems with Web2
- Web3 example
- How TF to access Web3

Without further ado,...let's go!!😆
In short:

Web 3.0 = Web 2.0 + decentralization

Web3 is anything you currently use in the internet and decentralizing it.

This is the short version, but let’s take a look at it in more detail 👇
Read 22 tweets
Sep 23, 2021
Blockchain is the FUCKING future🔥

NOW is the time to learn Web3 + blockchain development!!

A roadmap for blockchain development + resources👇

A thread 🧵
There is no concrete roadmap for this field yet, as it's still VERY new, but here's a quick roadmap 🗺️

-Web dev basics
-Blockchain fundamentals
-Crypto basics
-Blockchain wallet
-Ethereum/Bitcoin
-Mining
-Solidity
-Smart contract
-Web3.js
-Truffle & Ganache
-dApp
1️⃣ @DappUniversity

This guy is a self-taught Blockchain dev that provides YouTube tutorials and roadmaps on the blockchain, and teaches crypto as well!

He also has a bootcamp you can sign up to for FREE!!

youtube.com/c/DappUniversi…
Read 8 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

Don't want to be a Premium member but still want to support us?

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!

:(