Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Itai Shin
9,928 Pointswhat is "margin"?
Hi
I just started to learn css, and I did not understand what
max-width : 940px and 0 auto is.
Can I have explanation?
Thanks :-)
4 Answers
Lee Anderson
5,717 PointsMax-widh : 940px means that the maximum with of your element is 940 px, it can be smaller but no bigger than that. No matter the resolution.
Margin clears the area around your element, outside the border. 0 auto margin tells you that there is no margin on top and bottom and auto tells the browser to keep even space on the left and the right sides of your element.
Hope this helps and enjoy learning!
Yaroslav Kleshchev
8,744 PointsMargin is the spacing between elements. Max width say the the max a element will every be is 940px. Auto means that the browser will calculate the value.
Mark Glissmann
7,225 PointsItai, I use Chrome as a browser and the developer tools helped a ton with questions regarding things such as this. You can hover over elements and it will display the padding, margin, border and size of the element.
Tyler Anyan
2,976 PointsIndeed, the best way to really understand it is to dig in with dev tools, as Mark stated above. Basically, imagine a div (or any block-level container) as a literal box. The content you want to display (text, images, etc..) goes inside the box. Margin would be the space outside the box, as if you were to put an invisible force field that keeps it a certain distance from other boxes; padding would be much like the word implies, the same as if you were to throw some sort of padding, or spacing, on the inside of that box in order to keep the contents a certain distance from the edges, or border, of the containing box.
Tyler Anyan
2,976 PointsApologies for basing my answer off the title of the post and not the actual meat of the question. A combo of all 3 answers here should give you a good understanding though.