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 trialYashwin Gokavarapu
Courses Plus Student 1,509 PointsDiffrence between padding and margin
i am not able to clearly understand the difference when i am trying to increase the size of my header bar i see only the padding is making difference but the margin dose not make any diifrence
6 Answers
Nicholas Olsen
Front End Web Development Techdegree Student 19,342 Pointscheck out css-tricks for a thorough explanation of the box model.
The straightforward answer to your question is that the padding is on the inside of the border, while the margin is on the outside of the border. So if you want to increase the space between the content of an element (perhaps some text) and the elements border, then you would increase the padding. But if you wanted to increase the spacing between the element and other elements around it then you would increase the margin.
I made this jsfiddle to illustrate.
notf0und
11,940 PointsMargin is on the outside of block elements while padding is on the inside.
Use margin to separate the block from things outside it
Use padding to move the contents away from the edges of the block.
Taken from a quick Google Search: http://stackoverflow.com/questions/2189452/when-to-use-margin-vs-padding-in-css
Janek Rezner
12,973 PointsMargin is on the outside of an element and padding is on the inside.
robinbehroozi
15,912 PointsHey Yashwin,
There is a video about the CSS Box Model at http://teamtreehouse.com/library/css-foundations/the-box-model/the-css-box-model-concept-3 that explains it really well.
Janek Rezner
12,973 Pointsyou should also look up (and always use) Box-sizing: Border-box; which makes your borders sit inside an element
Robert Ho
Courses Plus Student 11,383 PointsPadding is the space between the content and the sides (like the borders) of an element whereas the margin is the space between the element and everything outside of the element. So basically, use margin to separate the your block element from things outside of it and use padding to move content away from the edges of the block element.
here are some solutions from stackoverflow:
http://stackoverflow.com/questions/2189452/when-to-use-margin-vs-padding-in-css http://stackoverflow.com/questions/5958699/difference-between-margin-and-padding
Good luck!