{"id":352,"date":"2007-01-25T12:14:55","date_gmt":"2007-01-25T12:14:55","guid":{"rendered":"http:\/\/neosmart.net\/blog\/2007\/padding-and-margin-ndash-whats-the-difference\/"},"modified":"2007-01-25T12:34:32","modified_gmt":"2007-01-25T12:34:32","slug":"padding-and-margin-ndash-whats-the-difference","status":"publish","type":"post","link":"https:\/\/neosmart.net\/blog\/padding-and-margin-ndash-whats-the-difference\/","title":{"rendered":"&quot;Padding-&quot; and &quot;Margin-&quot; &ndash; What&#8217;s the Difference?"},"content":{"rendered":"<p>Many intermediate and begginer CSS designers get confused when it comes to padding and margin values. What&#8217;s the difference? They both just shift stuff, so why the different names? Don&#8217;t they do the same thing?\n<\/p>\n<p>Although the behavior of margin- and padding- is very similary, there is one important difference: margin- is on the <em>outside<\/em> of the element, and padding- is on the <em>inside<\/em>. What this means is, one will apply the whitespace shift &#8220;after&#8221; the element begins (padding), and the other will apply the whitespace &#8220;before&#8221; the element begins (margin). Many times there is no visible difference, but sometimes there is &#8211; a big one.\n<\/p>\n<p><!--more--><\/p>\n<ul>\n<li>Colored backgrounds. Imagine a div tag with a colored background. If you apply &#8220;padding-top: 10px&#8221; you&#8217;re going to <em>lower<\/em> the text by 10px &#8211; but this &#8220;lowering&#8221; is going to take place <em>inside <\/em>the colored div, which will start in the same place as it always did. In the end, <em>your colored section<\/em> will be 10px larger. If you had used the &#8220;margin-top&#8221; property instead, you would have lowered the entire div, and the text along with it. Your colored section <em>would not<\/em> change in size. <\/li>\n<li>Negative values. You can use &#8220;margin-left: -10px&#8221; and end up moving an element 10px over to the right &#8211; actually making it float on top (or under) the neighboring element, because you&#8217;re changing where the element begins (-10 from the left). But you <em>can&#8217;t<\/em> use negative values with &#8220;padding-&#8221; because then you&#8217;d be telling it something like &#8220;start the contents -10px before the container for this text even begins;&#8221; which obviously isn&#8217;t possible. You can drag the entire element over to the right (margins), but you can&#8217;t place the number 2 before the number 1 (padding), that&#8217;s just illogical! <\/li>\n<\/ul>\n<p>That&#8217;s all you need to know about padding and margins, but it&#8217;s useful to remember one more thing: when &#8220;zeroing out&#8221; a element (to get rid of all default margins), be sure to set <em>both<\/em> the padding and margin to 0. Depending on which browser interprets your page, it may place the default spacing as either a margin <em>or<\/em> a&nbsp;padding, and you have to be sure you get them both.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many intermediate and begginer CSS designers get confused when it comes to padding and margin values. What&#8217;s the difference? They both just shift stuff, so why the different names? Don&#8217;t they do the same thing? Although the behavior of margin- &hellip; <a href=\"https:\/\/neosmart.net\/blog\/padding-and-margin-ndash-whats-the-difference\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[73,169,125],"class_list":["post-352","post","type-post","status-publish","format-standard","hentry","category-software","tag-css","tag-html","tag-web-design"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4xDa-5G","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/comments?post=352"}],"version-history":[{"count":0,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/posts\/352\/revisions"}],"wp:attachment":[{"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/media?parent=352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/categories?post=352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/neosmart.net\/blog\/wp-json\/wp\/v2\/tags?post=352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}