Go Back To: Web Community or All Web Notes
CSS or XHTML Validation: If you had a choice
Written By ldragon on Apr. 30, 2008.
10 Comments
Report Note
+ Clip This
Hey people :) just been discussing this with my mates at work:
"Concerning all the websites you've ever made and are ever going to make, consider this: If you had to make sure that the site in question was 100% valid in either CSS2 or XHTML in order to finish, what would you choose?"
Personally, I'd probably stick with the XHTML validation, since I reckon this is more important overall i.e. for screen-readers, usability/accessibility issues.
Your thoughts?
elliothere
Written Apr. 30, 2008 / Report /
XHTML. Honestly, I really don't care if my CSS validates--usually it probably doesn't, since I'm usually using stuff like opacity, the appropriate IE filters, and maybe some Safari text shadows and whatnot.
Oli
Written Apr. 30, 2008 / Report /
XHTML every time but invalid CSS causes just as many problems.
At work I've had to try and fix a complete CSS hacktastrophe and it's been a nightmare. There are few reasons to *need* to hack CSS. You can usually get around the problem by refactoring your XHTML.
I just wish I could meet the "developer" who originally coded some of this crap so I could poke them in the eye with a sharp stick.
Mike
Written Apr. 30, 2008 / Report /
My CSS is constantly invalid because I use proprietary -webkit and -moz styles. Nothing I'm going to do about that.
I disagree, there are still some things that cause problems. If you're a validation stickler (or a best practices stickler) then using conditional comments to include IE-specific CSS stylesheets is still best way to do it. I, however, am lazy, and when I'm hacking things to work in IE6 then I use the underscore hack.
Also, Oli, how would you handle giving a JPG to IE6 and a PNG to everyone else by simply refactoring your HTML? ;)
markupninjas
Written Apr. 30, 2008 / Report /
First post, and right up my alley. I do hope I don't come off as an elitist though =\
I actually do agree. I think hacks are a crutch that infected the Web Standards movement early on along with laziness.
Your CSS / CSS-P toolbox is -huge- and you can typically find a workaround that will work. Sure, vertical centering is all but impossible without hacks or really shady voodoo things going on, but with all the layouts I've done, I've yet to encounter much you super duper need a hack for.
I like to use Overflow Hidden quite a bit as an alternative to clearfix type situations, but that and height: 1%; for has-layout bugs are really my "hack" toolbox, and overflow hidden is actually in the Spec, so I don't have many qualms about it. I dread the day that the height: 1% blows up IE-Next though.
I'm a firm believer that, by focusing on your core markup, and debugging at the core before diving into a hacked solution is the best and easily possible way. It all comes down to whether or not you have the gumption to wade through the wrappers and the css to find the bug. I'm also a firm believer that no hacks are possible on many many layouts.
To circle back to the OP, I've had 3 instances that CSS validation has saved my tail, and a bajillion instances that XHTML validation has tracked down that bug I couldn't, or showed me a glowing path to the bug atleast. I'd have to vote for XHTML validation. Though, like Oli says, the CSS bit is just as important (that ' that lined up with a scratch in my monitor seriously killed me till I broke down and validated).
I also lean heavily toward XHTML validation because of Coda to be honest. Coda has a nice feature where it "english's" out these validation errors, and shows you inline while you code where they are. I flip it on always. When I mess up, I know it immediately. It's a bit annoying at first, but it kicks a ton of ass by the time your done.
Good friggin post ldragon!
ldragon
Written May. 1, 2008 / Report /
Thanks mate :) That Coda feature you mentioned last sounds pretty fantastic, wish they'd just release it on Windows so i don't have to set up a dual-boot system on my new laptop :(
Well said. We have a few problems with that at work on our current project. The main bugs we were having were floating and using absolute and relative. The biggest issue we always come across is double side margins on floating elements in IE6. Now we can either do it as normal, and add a hack, or add an extra div with padding but no width, the width coming from the inner div.
When it comes to hacks in CSS, it's a choice: either add the hack, or add extra markup to get round it. Both methods have pros and cons, so it's the developer's choice.
markupninjas
Written May. 1, 2008 / Report /
hmmm I always try to fake the margin with relative positioning, padding instead of margin or I'll fall back on height 1% ( not so reliable for that one but sometimes its the rabbit out of the hat) extra markup sucks, but I'll choose it any day over the hack. Question is whether the devs wanna implement it ha!
Mike
Written May. 1, 2008 / Report /
With the double float margin bug, I always make sure to use padding instead. Once you discover the bug, then it's basically stuck in your mind so you tend to code around it. I haven't encountered it in awhile.
Oli
Written May. 2, 2008 / Report /
Extra markup is much easier to debug because you're putting in there so every browser behaves the same. If that's not the case, you've done something wrong.
Mike: in answer to your PNG question: I wouldn't swap it for a JPG (primarily because if I'm using a PNG, that probably means there's alpha-trans going on). I'd use a JS hack. Quick, easy and it's not garbing up my mark-up or presentation code.
Mike
Written May. 2, 2008 / Report /
Well for the new 9rules, I have a lot of PNG fancy stuff going on in the header. For IE6 I killed the lines in the background, made it a straight gradient, then took screenshots of exactly what it looked when layered and then made those images the backgrounds on the specific elements. I never use the alpha filter hacks because they never really work right, plus it takes a second or two after the page loads for it to actually show up. What type of JS hack would you do?
lalindsey
Written May. 2, 2008 / Report /
XHTML, just for the accessibity/usability factors. I always make sure my CSS is clean though but I don't regularly go and validate mostly because if I am checking cross browser myself I can tell if there is a problem, and I really rarely ever use hacks (I do however make extensive use of ie conditionals).