Mon. February 18, 10:28:44 PM
Looks like a good idea. They make CSS closer and closer to a programming language every day, don't they?
This article is no longer my most current version of CSS Diagnostics. Please see my latest article A Second Look At CSS Diagnostics for the latest version.
I've been getting so many hits on this article that I decided to update it. I have added a few more elements and attributes and changed the colors around. The most severe code is colored red while less severe is colored yellow. There is also a medium severarity that is colored orange. Also remember that elements have solid borders while attributes have dotted boreders. Also check out my Test Suite showing examples of CSS Diagnostics in action.
The other day I was reading Eric Meyer's blog and stumbled across his version of what he likes to call CSS diagnostics. So what is CSS diagnostics? It's a method to highlight those ugly spots in your code, you know <font color="red" size="+1">. Yeah under the hood, somewhere on your website garbage like that exists, yet it's always so hard to hunt down and fix. Never fear CSS diagnostics is here!
CSS Diagnostics allows users to find deprecated elements using CSS and also find find deprecated attributes using CSS. Sorry to have to repeat myself so much here, I'm trying to rank high in SEO with some of these terms since this is still very much uncharted territory.
So how do you use CSS Diagnostics? It's easy! It requires a pretty good knowledge of CSS 2 & CSS 3 selectors and a good knowledge of deprecated HTML elements and attributes.
applet, basefont, center, dir, font, isindex, menu, s, strike, u, marquee, blink, acronym /* html 5, use abbr */
{ border: 5px solid red !important; }
br[clear], hr[noshade], *[color],
*[bordercolorlight], *[bordercolordark], *[bordercolor], *[background], *[bgcolor], *[nowrap],
body[alink], body[link], body[text], body[vlink],
body[bottommargin], body[leftmargin], body[rightmargin], body[topmargin], body[marginheight], body[marginwidth],
ol[compact], ul[compact], *[start],
img[hspace], img[vspace]
*[align], *[valign],
*[height], *[width],
ul[type], ol[type], li[type],
basefont[size], font[size], hr[size]
{ border: 5px dotted red !important; }
input[type="button"], input[type="reset"], input[type="submit"],
tt, embed,
big, small
{ border: 5px solid orange !important; }
a[target], table[cellpadding], table[cellspacing],
map[name], img[name], object[name], form[name], iframe[name], a[name],
table[border], img[border], object[border], input[border],
object[classid], object[codebase], embed[quality], embed[pluginspage]
{ border: 5px dotted orange !important; }
div:empty, span:empty, li:empty, p:empty, td:empty, th:empty
{ padding: 20px; border: 5px solid yellow !important; }
*[alt=""], *[title=""], *[class=""], *[id=""], a[href=""], a[href="#"]
{ border: 5px dotted yellow !important; }
Place this code at the end of your stylesheet:
/* Deprecated Elements */
applet, basefont, center, dir, font, isindex, menu, s, strike, u, marquee, blink, acronym /* html 5, use abbr */
{ border: 5px solid red !important; }
/* Deprecated Attributes */
br[clear], hr[noshade], *[color],
*[bordercolorlight], *[bordercolordark], *[bordercolor], *[background], *[bgcolor], *[nowrap],
body[alink], body[link], body[text], body[vlink],
body[bottommargin], body[leftmargin], body[rightmargin], body[topmargin], body[marginheight], body[marginwidth],
ol[compact], ul[compact], *[start],
img[hspace], img[vspace]
*[align], *[valign],
*[height], *[width],
ul[type], ol[type], li[type],
basefont[size], font[size], hr[size]
{ border: 5px dotted red !important; }
/* Proposed Deprecated Elements */
input[type="button"], input[type="reset"], input[type="submit"],
tt, embed,
big, small
{ border: 5px solid orange !important; }
/* Proposed Deprecated Attributes */
a[target], table[cellpadding], table[cellspacing],
map[name], img[name], object[name], form[name], iframe[name], a[name],
table[border], img[border], object[border], input[border],
object[classid], object[codebase], embed[quality], embed[pluginspage]
{ border: 5px dotted orange !important; }
/* Empty Elements */
div:empty, span:empty, li:empty, p:empty, td:empty, th:empty
{ padding: 20px; border: 5px solid yellow !important; }
/* Empty Attributes */
*[alt=""], *[title=""], *[class=""], *[id=""], a[href=""], a[href="#"]
{ border: 5px dotted yellow !important; }
It's a good idea to create consistency with your rules. I chose to highlight all attributes in a solid border while highlighting all elements in a dotted border. Also choose different colors for different meanings.
It should also be pointed out that you should use the most standards complient web browser when checking for results. Currently I found that Firefox 2 seems to work best as it comes with many other addons that can work side by side with the custom CSS.
I enjoyed reading Eric's ideas on it but felt I could expand it a bit more. Certainly other's can expand on my version as well. Feel free to contact me if you see something I'm missing.
Tags: css, css diagnostics, html, validation ( Add Tag )
Looks like a good idea. They make CSS closer and closer to a programming language every day, don't they?
I was really surprised when I applied this CSS to my dev site how many highlighted elements and attributes there are.
A lot of the CSS 3 selectors are getting really complicated and is starting to look a lot more like regular expressions than style markup. Personally I like it because as HTML gets more and more complicated, we'll need more ways to select the elements within it.
As far as CSS being a programming language, I see job postings out in California for full time CSS designers...what a dream job.
Firefox users who have the Web Developer add-on can use all this in an extra-cool way: Turn on css editing, go to the css window, scroll to the bottom, and paste in all the code above. You get instant highlighting of all the problems without ever affecting what other visitors to your site will see. (Just plugging it into your css files will highlight your problems for the world to see, but this is a way around that!)
Thanks for the great code!
W
You can also use the Firefox Accessibility Extension paste this into a custom user stylesheet and turn it on and off whenever you like. I'll have to try your method as well. Thanks for the post!
Very helpful stuff. Maybe if I'm good I can start getting into CSS again ;)
are b, i or u deprecated elements?
Alla, no they are not, although I group them in my "proposed deprecated elements" group since they can already by done with CSS. I have since updated this code so check out my most recent article @ http://www.nealgrosskopf.com/tech/thread.asp?pid=17
Site Coded And Designed By Neal Grosskopf Using No Crappy CMS Or Themes