开发者

Is there a way i can write css attributes targeted specifically for IE8,7,6 in a CSS file

I want to uses some css attibutes only for IE 6,7,8 in a css file. is it possible? Is it possible to target specific version of IE for each attribute.

somthing like this开发者_Go百科:

.mystyle {
   top:5px
   top:-30px //only if ie6
   top:-5px  //only if ie8
}

i know about <![If lt IE7]> tags but, i dont want to create one more css file.


This script is tiny, and filled with awesome: http://rafael.adm.br/css_browser_selector/

It will put classes on the HTML element that correspond to the user's browser. That will let you do things like this:

.ie7 .mystyle { top:5px;}
.ie8 .mystyle { top:-30px;}

I wouldn't create a new external javascript file just for this script. Its so small that I usually just add it to the top of my existing external javascript file.


there are a number of hacks you can use in your stylesheets themselves but this is generally considered bad practise. Here is an example

Why don't you want to use multiple stylesheets?

inspired by Stephen's post you could do this (stolen from html5 boilerplate by paul irish):

<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
<!--[if IE 7 ]>    <html lang="en" class="ie7"> <![endif]-->
<!--[if IE 8 ]>    <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9 ]>    <html lang="en" class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en"> <!--<![endif]-->

Final edit

should explain. If you add this to the html you will conditionally set an IE overriding class. The final line renders no class if browser is greater than IE9 (none) or not IE


You can use IE hacks, which will achieve what you're looking for. However, it's not advised to do that; long term maintenance will become difficult.

The conditional comments solution is the easiest and cleanest solution, and it's supported by MS. You should use them.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜