<p>I've seen numerous people mentions that you shouldn't use widths and padding or margins on the same element with CSS. Why is that?</p>

[{'answer_id': 75758, 'author': 'Stephen Deken', 'author_id': 7154, 'author_profile': 'https://Stackoverflow.com/users/7154', 'pm_score': 4, 'selected': True, 'text': '<p>Because some browsers treat the width as the total width of the element including the padding and the margins, and others treat the width as the base width to which the padding and margins are added.  As a result your design will look different in different browsers.</p>\n\n<p>For more information, see the <a href="http://www.w3.org/TR/CSS2/box.html" rel="noreferrer">W3C page on Box Model</a> and <a href="http://www.quirksmode.org/css/box.html" rel="noreferrer">quirksmode\'s take</a>.</p>\n'}, {'answer_id': 75789, 'author': 'Peter Boughton', 'author_id': 9360, 'author_profile': 'https://Stackoverflow.com/users/9360', 'pm_score': 2, 'selected': False, 'text': "<p>I've never come across a problem caused by using width, padding and/or margin together.</p>\n\n<p>So long as you have a valid DOCTYPE and are not in Quirks Mode, you will have a predictable box model and therefor should use whichever is most appropriate out of margin/padding to represent what you are trying to do.</p>\n\n<p>Note:\nMargin applies outside of borders, padding applies inside of borders.\nWidth means inner width of the container, the Total width = margin+border+padding+width (remembering that the first three are added for both left and right hand side).</p>\n"}, {'answer_id': 75797, 'author': 'Chris Serra', 'author_id': 13435, 'author_profile': 'https://Stackoverflow.com/users/13435', 'pm_score': 0, 'selected': False, 'text': "<p>Are you stating that padding and/or margin values shouldn't co-exist with a DOM element that also has a width value assigned to it?  If so, that is only true if you do not want to write CSS that is compatible with both IE as well as browsers which implement web standards (e.g. Firefox).  It would be difficult to achieve the layout you're looking for usually without some margin or padding value.  But I suggest that you write CSS that is compatible for both browsers.  If this is not what you are asking, then please correct me :)</p>\n"}, {'answer_id': 75811, 'author': 'spinodal', 'author_id': 11374, 'author_profile': 'https://Stackoverflow.com/users/11374', 'pm_score': 0, 'selected': False, 'text': '<p>The reason may be the famous <a href="http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug" rel="nofollow noreferrer">box model problem</a>.</p>\n\n<p>Summary: IE renders <em>width</em> different then the standard rendering if padding and margin used with width or height.</p>\n'}, {'answer_id': 75833, 'author': 'Jonathan Arkell', 'author_id': 11052, 'author_profile': 'https://Stackoverflow.com/users/11052', 'pm_score': 0, 'selected': False, 'text': '<p>I can think of 2 reasons:</p>\n\n<p>1) the old "box model" of IE is really flaky, so when you have an element with the style { width: 300px; padding: 30px; margin: 20px;} it\'s outline might not actually match up to the expected 400px (300 px size, plus 2 30px padding, plus 2 20 px margin.  I think its actual width would be 340, as it rolls the padding into the width calculation.</p>\n\n<p>which brings is to...</p>\n\n<p>2) Some people find the calculations a little confusing. </p>\n\n<p>That said, I personally use widths along with padding and margins and have no problems with it.  If you limit yourself to not using widths when using paddings/margins, that means you are peppering your code with a lot of non-semantic cruft.  It does mean you have to be aware of what the various browsers are going to do with the element, but this is why we browsertest.</p>\n'}, {'answer_id': 76987, 'author': 'David Heggie', 'author_id': 4309, 'author_profile': 'https://Stackoverflow.com/users/4309', 'pm_score': 2, 'selected': False, 'text': '<p>A lot of people still cling to notions about faulty box-models in IE and reckon that if you start messing around with element widths, padding and margins, you\'re going to get into trouble.</p>\n\n<p>That\'s pretty outdated advice - assuming you\'re using <a href="http://alistapart.com/articles/doctype/" rel="nofollow noreferrer">a correct doctype</a>, all fairly modern browsers (including IE6+) will work to the same box model, and you shouldn\'t really have too many issues related to it.</p>\n\n<p>This being CSS, you will obviously have a million <em>other</em> cross-browser issues, but the infamous IE box-model is becoming a thing of the past.</p>\n'}, {'answer_id': 78455, 'author': 'nickf', 'author_id': 9021, 'author_profile': 'https://Stackoverflow.com/users/9021', 'pm_score': 0, 'selected': False, 'text': '<p>One important point to note is that it can make using percentage widths almost impossible. Take this for example, if you want your "content" div to take the full width, but have a 10px padding:</p>\n\n<pre><code>#content {\n    width: 100%;\n    padding: 0 10px;\n}\n</code></pre>\n\n<p>That works in the (sensible, but incorrect) IE model, but in standards compliant browsers your div will occupy a width of 100% + 20px which is no good. The solution is to use another "inner" container.</p>\n\n<pre><code>&lt;div id="content"&gt;\n    &lt;div class="inner"&gt;\n        content here.\n    &lt;/div&gt;\n&lt;/div&gt;\n\n#content {\n    width: 100%;\n}\n#content .inner {\n    padding: 0 10px;\n}\n</code></pre>\n\n<p>It\'s a bit annoying have the extra markup, but it makes a lot of things easier in the long run.</p>\n'}]
['https://Stackoverflow.com/questions/75732', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/12930/']