Yeah what is the difference in margin and padding? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Yeah what is the difference in margin and padding?

Aren't they basically the same.

9th May 2020, 10:00 PM
Joel Sanders
Joel Sanders - avatar
5 Answers
+ 3
To expand on Arb Rahim Badsa code and example Blue = margin Black = border Red = padding Yellow = element/content https://code.sololearn.com/Wr4uQ3E94uWa/?ref=app
9th May 2020, 11:03 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Joel Sanders Hey there, they aren't the same. Consider the following example : Margin : ------------------------ | | | | | | | | ------------------------ Imagine, this is a box. The margin will determine where it should from it's parent. For example, if you set the margin of this box 20px: it will look like : 20px | ------------------------ | | | | --20px--| |--20px-- | | ------------------------ | 20px Here is a code sample :)) https://code.sololearn.com/WQO492Almp7V/?ref=app
9th May 2020, 10:28 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 2
And for padding : Padding is what specifies how far your content should from the border inside the box. Check the code. The text 'I am padding' is 15px left, 15px top, 15px bottom and even 15px right from the box's borders. This is what padding is :))
9th May 2020, 10:34 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
Oh ok I see what you mean that last example was very helpful! Thank you for the excellent detail and time you put in! :)
9th May 2020, 11:27 PM
Joel Sanders
Joel Sanders - avatar