{"id":138,"date":"2008-05-26T20:31:21","date_gmt":"2008-05-27T01:31:21","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=138"},"modified":"2008-05-26T20:31:21","modified_gmt":"2008-05-27T01:31:21","slug":"deprecated-element-highlighting","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/deprecated-element-highlighting\/","title":{"rendered":"Find Deprecated Elements with Diagnostic CSS Highlighting"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/05\/diagnostic-400.gif\" alt=\"\" title=\"diagnostic-400\" width=\"400\" height=\"150\" class=\"alignnone size-full wp-image-140\" \/><\/p>\n<p>I have to admit that I\u2019m a bit of a code purist. In my heart of hearts, I\u2019d really like to think that every developer out there that this site helps will turn around and produce clean, semantic XHTML to which to apply their lovely, efficient CSS. But that isn\u2019t always the case. Sometimes people write code that isn\u2019t quite semantic, whether they\u2019re in a rush or just don\u2019t know any better. Or sometimes designers are charged with redesigning a website that was first built during the Neolithic period. <\/p>\n<p>Any way you slice it, there\u2019s still a lot old-skool code floating around out there, and it can be a bear to dig through all that HTML to find the bits that could use a good refreshing. So once again, CSS comes to the rescue! The technique I\u2019m talking about today is sometimes called \u201cCSS Diagnostics.\u201d Basically, you\u2019re just using CSS to highlight specific elements and attributes \u2013 specifically, the ones that shouldn\u2019t even be there in the first place.<\/p>\n<p>Our first order of business is to decide what elements you\u2019d like to weed out of your code. You could create a list of every single deprecated tag out there, but most developers didn\u2019t use every tag out there. For our purposes, I\u2019m going to look for the &lt;font&gt;, &lt;center&gt;, &lt;s&gt; (strikethrough), &lt;u&gt; (underline), &lt;b&gt; (bold), and &lt;i&gt; (italic) tags, which probably make up around 80% of the still-common deprecated tags out there. If I want to see where those tags are used in any website, all I need to do is apply some CSS to make them stand out:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">font, center, s, u, b, i {\n\tcolor: #000;\n\tfont-weight: bold;\n\tbackground-color: #f99;\n\tborder: 3px solid #c00; }<\/pre>\n<p>And just like that, all of our deprecated tags are boldfaced on a light red background with a nice, wide dark red border. And assuming that wasn\u2019t your previous design of choice (please tell me that wasn\u2019t your previous design of choice), they should stand out on your website like the big, red sores that they are. :)<\/p>\n<p>And that takes care of our tags, but what about all those deprecated attributes out there that might be applied to perfectly legitimate tags? For that, we\u2019ll use the magic of <a href=\"\/css-attribute-selectors\/\">CSS attribute selectors (more on those here).<\/a> So for example, if I knew that the previous developer of the site I\u2019d just inherited was fond of applying margins to their body tags using \u201crightmargin,\u201d \u201cleftmargin,\u201d and so on, and also loved to scatter \u201cbgcolor\u201d and \u201cbackground\u201d attributes like so many apple seeds, I could just write a rule like this to weed them out:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">body[bottommargin], body[leftmargin], \nbody[rightmargin], body[topmargin],\n*[background], *[bgcolor] {\n\tcolor: #000;\n\tfont-weight: bold;\n\tbackground-color: #fc6;\n\tborder: 2px solid #c60; }<\/pre>\n<p>Here I\u2019m using attribute selectors to highlight elements with particularly unsavory attributes. I\u2019m also using the universal selector (*) to find all instances of attributes that can apply to multiple types of elements (like backgrounds). That way, I don\u2019t have to write out every possible combination of element and attribute under the sun. And just like that, I\u2019ll be able to hunt down all sorts of problem bits of code! <a href=\"\/example\/highlight-deprecated\/\">You can see our examples from above in action here.<\/a><\/p>\n<p>A few words of caution: when you\u2019re doing this sort of styling, it\u2019s important to apply these styles <em>after<\/em> all of your other CSS has been applied. That way, you don\u2019t accidentally overwrite parts of your diagnostic CSS with other rules later on down the line. To do that, either put your diagnostic rules at the bottom of your CSS files, or create a whole new file for your diagnostic rules and &lt;link&gt; them after your main CSS file, or just copy and paste them into a &lt;style&gt; tag if you\u2019re only diagnosing a page or two.<\/p>\n<p>Also, as mentioned in the last article about attribute selectors, IE6 doesn\u2019t recognize them. Of course, since this are purely diagnostic rules, that shouldn\u2019t be much of a problem&#8230; just be sure to view your website in a modern browser (Firefox, Opera, Safari, IE7 (if you must), etc) when checking it for problems. And really, if you\u2019re still using IE6 for all of your web design work, you\u2019ve bigger issues to work through than just a deprecated tag or two here and there. :)<\/p>\n<p>And finally, this build-your-own-diagnostic method is great if you know what to look for, but if you\u2019d prefer a more one-size-fits-all solution to your diagnostic woes, I\u2019d suggest downloading a <a href=\"http:\/\/www.nealgrosskopf.com\/tech\/thread.asp?PID=3\">full diagnostics stylesheet, like the one Neal Grosskopf offers here.<\/a> However, be aware that his solution will highlight elements and attributes that are technically deprecated but still commonly used to good ends \u2013 such as the \u201cheight\u201d and \u201cwidth\u201d attributes on images. I may be a code purist, but I still find those attributes mighty useful!<\/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>I\u2019d really like to think that every developer out there that this site helps will turn around and produce clean, semantic XHTML to which to apply their lovely, efficient CSS. But that isn\u2019t always the case. So once again, CSS comes to the rescue! [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/deprecated-element-highlighting\/\" title=\"Click to read 'Find Deprecated Elements with Diagnostic CSS Highlighting'\">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,170,192],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/138"}],"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=138"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}