{"id":100,"date":"2008-04-23T07:00:55","date_gmt":"2008-04-23T12:00:55","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=100"},"modified":"2008-04-23T07:00:55","modified_gmt":"2008-04-23T12:00:55","slug":"reset-style-sheets","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/reset-style-sheets\/","title":{"rendered":"Level the Playing Field with Reset Style Sheets"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/04\/reset-css.gif\" alt=\"\" title=\"reset-css\" width=\"400\" height=\"173\" class=\"alignnone size-full wp-image-101\" \/><\/p>\n<p class=\"guestbio\"><a href=\"http:\/\/www.scottphillips.info\/\">Scott Phillips<\/a> is a web developer working at Drake University in Des Moines, Iowa.<\/p>\n<p>The most frustrating part of learning cascading style sheets is getting consistent results across browsers. As you probably know, not every browser supports every rule in the same way (or at all).<\/p>\n<p>Luckily, strategies have emerged that can help CSS newbies keep their sanity. The first is to write CSS so that it works in a browser that has solid support for CSS (like FireFox or Opera) and later tweak it, as needed, to work correctly in others (like IE6). Another strategy is to use a <a href=\"http:\/\/validator.w3.org\/\">validator<\/a> to find any simple syntax mistakes. These days, more and more developers are using a reset style sheet to cancel out pesky differences between browsers.<\/p>\n<h3>What&#8217;s the problem?<\/h3>\n<p>Even when you don&#8217;t use CSS in your web pages, you are still using CSS in your web pages. Huh? I&#8217;ll explain. Begin with the simplest page you can imagine:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;html&gt;\n\t&lt;h1&gt;Here is my title.&lt;\/h1&gt;\n\t&lt;p&gt;Here is my paragraph.&lt;\/p&gt;\n&lt;\/html&gt;<\/pre>\n<p>View it with several browsers and you&#8217;ll see subtle differences. The margins are off. The font sizes and weights are different. We&#8217;ve hardly begun and already our pixel-perfect design is breaking down!<\/p>\n<p>Here is what&#8217;s happening. Every browser has built-in default styles. To see Firefox&#8217;s on Windows XP, for example, open the file C:\\Program Files\\Mozilla Firefox\\res\\html.css. You&#8217;ll find rules like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">h1 {\n\tdisplay: block;\n\tfont-size: 2em;\n\tfont-weight: bold;\n\tmargin: .67em 0;\n}\n...\nblockquote[type=cite] {\n\tdisplay: block;\n\tmargin: 1em 0px;\n\tpadding-left: 1em;\n\tborder-left: solid;\n\tborder-color: blue;\n\tborder-width: thin;\n}\n...\nhr {\n\tdisplay: block;\n\theight: 2px;\n\tborder: 1px -moz-bg-inset;\n\tmargin: 0.5em auto 0.5em auto;\n}<\/pre>\n<p>The lesson is this. <strong>If you don&#8217;t express an opinion about how an element should look, the browser will substitute its own.<\/strong> We&#8217;ve already seen that browsers never agree. Furthermore, even if an element looks identical across browsers, you can&#8217;t assume it is actually being treated identically (i.e. one browser may use a default margin for the white space around a list while another uses padding).  Make a seemingly small adjustment and suddenly they both change in different ways. What a mess.<\/p>\n<h3>What can we do?<\/h3>\n<p>Zero-out the default browser styles. Then replace them with your own. A very simple reset rule looks like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">* {\n\tmargin: 0;\n\tpadding: 0;\n}<\/pre>\n<p>That cancels out margin and padding for all elements on the page. From here you might want to continue by resetting font sizes and removing image borders:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">html {\n\tfont-size: 1em;\n}\nbody {\n\tfont-size: 100%;\n}\n:link img, :visited img {\n\tborder: 0;\n}<\/pre>\n<p>It would also be handy to fix inconsistencies with lists and tables:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">table {\n\tborder-collapse:collapse;\n\tborder-spacing:0;\n}\nol,ul {\n\tlist-style:none;\n}<\/pre>\n<p>Slap all that code into a file called reset.css and @import it at the top of every page. You are on your way to more consistent results and fewer debugging headaches.<\/p>\n<h3>Standing on the Shoulders of Giants<\/h3>\n<p>Our reset style sheet is simple but effective but it&#8217;s just the beginning. The universal selector (*) can occasionally cause issues of its own. And inheritance problems can also crop up as you continue to expand your reset style sheet.<\/p>\n<p>Luckily, web pros like to share. Yahoo has released their own reset style sheet for us to use, called <a href=\"http:\/\/developer.yahoo.com\/yui\/reset\/\">Reset CSS<\/a>, as a part of the larger Yahoo User Interface (YUI) library. Eric Meyer, a full-fledged CSS Jedi, has also done a lot of work on a robust <a href=\"http:\/\/meyerweb.com\/eric\/thoughts\/2007\/05\/01\/reset-reloaded\/\">reset style sheet<\/a>. Both are excellent, and I recommend studying and adopting either (or parts of both) of them into your own projects.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<\/p>\n<p class=\"guestbio\">Scott Phillips is a web developer working at Drake University in Des Moines, Iowa.<\/p>\n<p>The most frustrating part of learning cascading style sheets is getting consistent results across browsers. As you probably know, not every browser supports every rule in [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/reset-style-sheets\/\" title=\"Click to read 'Level the Playing Field with Reset Style Sheets'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168],"tags":[112,111],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/100"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}