I had to include the following code in a website to make it crossbrowser compatible but it doesn't validate. <![if !IE]><style> #nav ul { top:-4px;}</style><![endif]> Code (markup): I believe it doesn't validate simply because it isn't XHTML, it's another language, but what language is it and how can I make it validate? Thanks, Michael
Does it even matter that it throws up validation errors on this, so long as the rest of the page is valid?
Use <!--[if !IE]><style> #nav ul { top:-4px;}</style><![endif]-->. I think that will solve your problem
Thanks belkocrnic but it didn't work. Instead it just made the statement into a comment and thus ignored it. Any other suggestions?
That is correct. These are IE Conditional Comments and do not work with any other browser so !IE statement doesn't make sense.
My recommendation: Instead of relying of conditional statements use JavaScript to provide you with specific browser selectors.
Ahh, that makes sense now. I can fix this by doing a little tweaking and changing !IE to IE then. Thanks drhowarddrfine! Just out of curiousity, are there any conditional statements that apply to other browsers such as FF and Opera that are still W3C valid?
Really? Well the original statement (in my first post) works in FF at the very least - it just doesn't validate.
Thanks Spawny but it's the actual condition (and the syntax of the condition) and not the statement itself that is throwing up the errors.
Instead of trying to make that rubbish hack work, perhaps you could just fix the page in question? Usually if you need to make that type of adjustment, there's bigger problems with the layout.
99.99% of the time if they are handling margins/padding differently, you either don't have a doctype, overthought your layout, or are 'doing it all wrong'.
For future reference, I was shown the site via PM, and the problem with the page in question was an XML prolog throwing IE into quirks mode combined with margin use tripping the buggy box model.