What's the difference between Auto , 0 auto and 0? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's the difference between Auto , 0 auto and 0?

What's the difference in these values of Margin . margin:0; / margin:0 auto; / margin:auto; I've seen it done even in padding.

13th Nov 2016, 10:18 AM
Sidepocket
Sidepocket - avatar
6 Answers
+ 1
margin:auto; You can set the margin property to auto to horizontally center the element within its container. margin:0; if you write only 0 you set all margins to 0 independent of window/Browser size.
9th Jan 2022, 4:25 PM
Rajveer
Rajveer - avatar
0
if you use margin, this ist a global setting of margin-top, margin-bottom, margin-right and margin-left. if you write one param after margin:, this means, that top bottom left and right are the same! if you use two params, (e.g. margin: 3 5) the 3 is for top and bottom and the 5 for left and right. so margin: 0 means => top=bottom=left=right=0 margin: 0 auto => top=bottom=0 AND left=right=auto margin: auto => top=bottom=left=right=auto hope that helps...
13th Nov 2016, 11:29 AM
jmey
0
Not really @Jmey, I really want to know why :0 auto; instead of just:0; What is it that : 0 auto; does that is different from :0;
13th Nov 2016, 11:42 AM
Sidepocket
Sidepocket - avatar
0
yes it differs, with 0 auto you set only top an bottom to 0, the left and right margin will be set automatic, depents on the window resolution. if you write only 0 you set all margins to 0 independent of window/Browser size.
13th Nov 2016, 11:58 AM
jmey
0
margin auto means: center the block margin 0 means set the margin to 0 but you have to set the display attribute to "block", without this your tags are floating.
13th Nov 2016, 12:13 PM
jmey
0
Now that's a clear answer@Jmey.... thanks a lot bro..
13th Nov 2016, 12:20 PM
Sidepocket
Sidepocket - avatar