Placed in: Home arrow Programming arrow CSS arrow CSS trick: Debug your HTML and CSS
CSS trick: Debug your HTML and CSS

Today, I'll be showing you a neat little CSS trick to Debug your HTML and CSS. Take note that this will not be actual debugging, but it can help you find the element depth on a web page. Also, when you didn't properly close a tag, this piece of code will expose it for you.

Debug your HTML and CSS

Simply check out the demo to view what we're going to create! At first, the demo looks like a regular web page. But when you start hovering the elements, you'll be able to see the HTML structure (in depth) of the HTML page.

Demo Debug your HTML and CSS   Download Debug your HTML and CSS

There are just a couple of lines of CSS to get this effect! Check out how (or view the source) you can create this yourself.

The Debug CSS

This little piece of code will give you the debugging effect. The * in CSS means any element; a * * means any child element etcetera. With the :hover the lines will only will displayed when hovering the page. Remove the keyword to see the full structure.

 
* *:hover { border:2px solid #89A81E }                   /* Solid Green */
* * *:hover { border:2px solid #F34607 }                 /* Solid Orange */
* * * *:hover { border:2px solid #5984C3 }               /* Solid Blue */
* * * * *:hover { border:2px solid #CD1821 }             /* Solid Red */
* * * * * *:hover { border:2px dotted #89A81E }          /* Dotted Green */
* * * * * * *:hover { border:2px dotted #F34607 }        /* Dotted Orange */
* * * * * * * *:hover { border:2px dotted #5984C3 }      /* Dotted Blue */
* * * * * * * * *:hover { border:2px dotted #CD1821 }    /* Dotted Red */

That's all there is! Simply add this to the top of your CSS file and remember the order. When in production, you can simply remove it (or place it in comments).

We don't need to check one *, since the first element it'll find is the <body> tag. Unless you're afraid of doing that wrong, you might want to add it too.

Conclusion and Download

This trick might get in handy just in case you didn't fully check something.

Demo Debug your HTML and CSS   Download Debug your HTML and CSS

The demo page was created with text from HTML-Ipsum. What do you think of this code?


Tags:  debug css trick html code snippet

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
Gaya   2009-10-13 22:50:49
Gravatar image Funny little trick. Still prefer using firebug though.
Keep up the good stuff!
Marco   2009-10-14 08:58:06
Gravatar image Haha, of course Firebug works better (but only in Firefox ;) ).

Thanks for the comment!
Jack F   2009-10-13 22:57:01
Gravatar image I know you wanted to use just HTML/CSS, which is cool. If you used jQuery, you could do the same thing but take 2px off the width/height of the item, so they wouldn't shift around. Just a thought.

Good idea though, very original.

Jack.
Marco - Thanks!   2009-10-14 08:57:27
Gravatar image Hi Jack!

Thanks - I know and you're absolutely right. Still, I wanted to make this a "full CSS s0lution". You might want to check and try this example from Chris Coyier about "breaking borders".
Janko   2009-10-13 23:05:42
Gravatar image Really nice and original idea!
5h4rk   2009-10-14 00:47:00
Gravatar image The idea is ingenious! It would be nicer if this works on IE6, with jQuery maybe?

@Jack or maybe you can use background colour instead of border.
Richard Tape - Firebug in IE/Opera/Safari too ;)   2009-10-14 09:43:28
Gravatar image FireBug also works in IE/Opera/Safari too in a "lite" form, by the way Marco. http://getfirebug.com/lite.html

Very useful tool.

However, I like your idea, it's really quite clever. Nice and 'quick' :)
Marco - Didn't know!   2009-10-14 10:02:26
Gravatar image Whoah - thanks Richard, didn't know that! Might give a shot too with other browsers later.

Glad you liked the "trick" :D !
Anonymous - Nice   2009-10-15 01:50:27
Gravatar image :) if there is no firebug,that is a good method.
kwa - mr   2013-04-23 14:52:56
Gravatar image please do you have a prozy site that I can use to access facebook. where I am I can't access facebook direct



THANKS
kwa - ME   2013-04-23 14:55:08
Gravatar image PLEASE DO U HAVE A PROZY SITE TO ACCESS FACEBOOK?
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Subscribe to Marcofolio