{"id":52,"date":"2008-03-12T07:00:36","date_gmt":"2008-03-12T12:00:36","guid":{"rendered":"http:\/\/cssnewbie.com\/five-quick-css-fixes\/"},"modified":"2008-03-12T07:00:36","modified_gmt":"2008-03-12T12:00:36","slug":"five-quick-css-fixes","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/five-quick-css-fixes\/","title":{"rendered":"Why Doesn\u2019t My CSS Work? Five Quick Fixes."},"content":{"rendered":"<p><img src='https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/03\/hammer-400.jpg' alt='large hammer' title='Photo by PPDIGITAL. Used under a Creative Commons license.' \/><\/p>\n<p>Imagine: You\u2019ve been working on your brand new, beautifully cascading style sheet for most of the day. You save your work, load it into a browser, and\u2026 what the heck?! Nothing\u2019s working right! You know you didn\u2019t make any huge errors in your code, but something is obviously wrong.<\/p>\n<p>We\u2019ve all been there before. But instead of wasting endless hours debugging your code, here are a few very simple things you can check in your CSS before you start pulling out your hair.<\/p>\n<p><strong>Closing brackets<\/strong> are notoriously easy to miss, especially if you don\u2019t put them on a line all by themselves (and I usually don\u2019t). Missing a single closing bracket can throw off your entire website, because the browser quits loading your rules as soon as it encounters the malformed code.<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.sidebar {\n\twidth: 200px;\n\tbackground-color: #333;\n.sidebar h3 {\n\t\/* None of these rules are applied! *\/\n\tfont-size: 1.4em;\n\tcolor: #fff; }<\/pre>\n<p>A <strong>missing semicolon<\/strong> can likewise cause your code to start behaving wonky. CSS specifications state that you don\u2019t need a semicolon on your very last rule before your closing bracket, but in my experience that\u2019s a great way to set yourself up for some heartbreak. As soon as you decide to add one more rule to that property, that missing semicolon is going to rear its ugly head.<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.sidebar {\n\twidth: 200px;\n\tbackground-color: #333\n\t\/* The following rule won't render! *\/\n\tpadding: 5px;\n}<\/pre>\n<p>Is there any chance you have a <strong>misspelled class or ID<\/strong>? It may sound obvious, but I\u2019ve spent far too much of my life trying to debug my CSS just because I misspelled something along the line. This, if anything, is a good reason to stick to whole words (or at least common abbreviations) when writing your CSS classes and IDs \u2013 it\u2019s going to be easier to notice a misspelling in the \u201cleftSidebar\u201d class than it is the \u201cltSdbr\u201d class.<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.siedbar {\n\t\/* Dunno what a siedbar is, but I'm\n\t   pretty sure it's not in my XHTML. *\/\n\twidth: 200px;\n}<\/pre>\n<p><strong>Misspelled properties or values<\/strong> have also caused me more than their fair share of trouble. There are certain words I tend to misspell when I\u2019m typing too quickly, and it just so happens that there are a lot of CSS properties with related names. I don\u2019t care how much I\u2019m \u201cin the zone,\u201d there\u2019s still about a 50% chance I\u2019m going to try to apply a \u201cbakcground-color\u201d somewhere along the line.<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.sidebar {\n\t\/* The following property does exactly \n\t   bupkis. Dyslexics Untie! *\/\n\tbakcground-color: #333;\n}<\/pre>\n<p><strong>Bad CSS values<\/strong> can be a bear to hunt down, particularly if you\u2019re convinced that the value you\u2019re using really exists. Some invalid values are more obvious than others \u2013 a background-color of \u201c1px\u201d would be relatively easy to spot, but what about a vertical-align of \u201ccenter,\u201d <a href=\"\/firefox-error-console-review\/\">like I mentioned last week?<\/a> We tend to think of things as being either aligned to the top, center, or bottom of a space&#8230; but CSS classifies that second option as the \u201cmiddle,\u201d not the center. An alignment of center won\u2019t create nearly the presentation you\u2019re expecting.<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">.sidebar img {\n\t\/* This image isn't really going anywhere. *\/\n\tvertical-align: center;\n}<\/pre>\n<p>If you start your CSS debugging by looking at these five common problem areas first, there\u2019s a good chance you\u2019ll save yourself a whole lot of time \u2013 and a massive headache to boot. If you have any other ideas for common areas of CSS misstep, offer them up in the comments!<\/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>Imagine: You\u2019ve been working on your brand new, beautifully cascading style sheet for most of the day. You save your work, load it into a browser, and\u2026 what the heck?! Nothing\u2019s working right! You know you didn\u2019t make any huge [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/five-quick-css-fixes\/\" title=\"Click to read 'Why Doesn\u2019t My CSS Work? Five Quick Fixes.'\">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":[192],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/52"}],"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=52"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}