Jump to content

W3C CSS validation question


Berniew

Recommended Posts

In order to adjust my style definitions to render a page the same in IE 6.0 and Firefox 1.5.04 I have added comments that are ignored by FF but acted on by IE. However these comments fail the W3C CSS validation test is there an alternate way to adjust style sheets when there are adjustments needed for IE?My CSS does pass validation if I don’t try to adjust for IE.

W3C CSS Validator Results for file://localhost/testing.cssErrorsURI : file://localhost/testing.css    * Line: 8 Context : body      Parse Error - <!--margin: 1% 0% 0% 0%;    * Line: 9 Context : body      Parse error - Unrecognized : }
body {  font-family: Georgia, "Times New Roman", Times, serif;  font-size: 1em;  color: #333333;  background-color: #F9F9F9;  margin: 0% 0% 0% 0%; /*top right bottom left*/  /* adjust for IE */  <!--margin: 1% 0% 0% 0%;-->}

Link to comment
Share on other sites

Place a star in front of the property instead, like this:

*margin: 1% 0% 0% 0%;

But please note it won't work in IE7. The best way to filter IE only styles is with conditional comments in your (X)HTML that point to the location of the stylesheet(s), like this:

<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="IE6style.css" /><![endif]-->

Where IE6style.css is the CSS file for IE6 and lower.

Link to comment
Share on other sites

I have tried to use the syntax from the example code you provided however the IE stylesheet is not used. Unless I am missing something.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head> <title>HTML CSS Test</title> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">  <link href="testing.css" rel="stylesheet" type="text/css"><!--[if lte IE 6]><link rel="stylesheet" href="testingIE.css" /><![endif]--></head>

Link to comment
Share on other sites

Just incase the problem is in the conditional comment itself, here is an article about conditional comments in MSDN.But from what I see, you are using HTML 4, so the code may be better working like this:

<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="testingIE.css"><![endif]-->

I realize the missing of the type attribute was my mystake. Sorry about that :) .

Link to comment
Share on other sites

Bottom line is you don't need hacks, take the time to fix them without hacks, believe me, anything can be done in css with almost any browser(within reason) without using any hacks, unless you are going back to ie nn 4 which is worthless anyway, you can get all things looking perfect without using any hacks at all, it just takes longer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...