开发者

I used special character '#' '_' and '\' for IE browser compatibility. But now my style sheet is fail in W3c validation because of using IE hack

I used special character '#' '_' and 开发者_高级运维'\' for IE browser compatibility. But now my style sheet is fail in W3c validation because of using IE hack. Is there anyway for error less stylesheet with browser compatibility.

Now I am not able to remove these IE hack because of my HTML files are now in Java program development.

My hack are like this :

/* For IE8 */top:-15px;

/* For IE7 */#top:-10px;

/* For IE6 */_top:-1px;


Yeah, don't use invalid CSS hacks, they're super-fragile.

For the specific case of picking up IE, conditional comments are better. Most solutions put extra stylesheets in CCs, but if you don't want to do that you can do class-switching with CCs:

<!--[if IE 6]> <body class="ie6"> <![endif]-->
<!--[if IE 7]> <body class="ie7"> <![endif]-->
<!--[if gte IE 8]><!--> <body> <!--<![endif]-->

and then do all your styling in one place based on the class:

#something { top:-15px; }
body.ie7 #something { top:-10px; }
body.ie6 #something { top:-1px; }

(This is assuming that IE8 is “all right” and should be served the same rules as other browsers, hence the ‘downlevel-revealed’ CC that allows everyone else to see the classless <body>.)


Used the particular html page in conditional statement.

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

Your reference

http://reference.sitepoint.com/css/conditionalcomments


Factor your adaptions for IE out into separate style sheets, and include them via conditional comments, e.g. for the IE8 style sheet:

<!--[if IE 8]
<link rel='stylesheet' href='ie8.css' />
<![endif]-->


I would say don't worry too much about validation.

It is helpful to use when trying to figure out when something is broken, but not the goal of any Web site.

Instead of hacks within your css, why not use conditional comments?

<!--[if lt IE 8]>
  //styles here
<![endif]-->

You can either place individual styles in there or a link to a stylesheet.

Either way, only IE less than 8 sees it.

http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx


There is also a solution without the conditional comments, which allows you to store all CSS rules in one file.

* html selector { /* rules for IE6 */ }
*:first-child+html selector { /* rules for IE7 */ }

For IE8, you shouldn't need any CSS hacks; it's a browser with very good CSS 2.1 support. If you, despite this fact, do need one, you may try setting a value with no hack and then rewrite it using some CSS3 selector that won't be recognized by IE8.

selector { /* rules for IE8 */ }
html:root selector { /* rules for IE9, Firefox, Chrome, etc. */ }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜