像往常一样,有些东西在FF中可以正常工作,但在IE中不能正常工作。所以我的问题是:有没有一种方法可以在css中插入只被Internet Explorer8识别的类属性。
.style1, .style2 .style3 {
height: 20px;
}我希望height属性只对IE浏览器可见(我使用版本8),因为高度在FF中显示正确,但如果我要在两个浏览器中插入height: 20px,那么在FF中就太多了,所以我只需要在IE中使用它。有办法做到这一点吗?
发布于 2011-01-11 19:58:56
正如其他人所指出的,条件样式表通常用于特定版本的IE。
我最近转向了一种更高效、更整洁的方式来管理条件样式,它减少了单独样式表的数量,并允许您将条件样式放入主样式表中。例如,你可以像这样实现你想要做的事情:
在您的网页中:
<!--[if lt IE 7]> <body class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]> <body class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]> <body class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]> <body class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]> <body class="ie"> <![endif]-->
<!--[if !IE]><!--> <body> <!--<![endif]-->在样式表中:
.ie8 .style1, .ie8 .style2 .i8 .style3 {
height: 20px;
}Paul爱尔兰和其他人有大量关于此方法的文档和测试用例。这是一个很好的起点:http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
发布于 2011-01-11 19:09:10
不是直接在css中,不是。但是,只有当浏览器是IE或IE的特定版本时,才能在html页面中使用conditional comments来加载css样式表:
<!--[if ie]>
<link rel="stylesheet" type="text/css" href="path/to/ie-stylesheet.css" />
<![end if]-->您还可以使用以下命令针对特定版本的IE执行此操作:
仅限IE 8
<!--[if ie 8]>
<link rel="stylesheet" type="text/css" href="path/to/ie-stylesheet.css" />
<![end if]-->IE版本高于IE 7
<!--[if gt ie 7]>
<link rel="stylesheet" type="text/css" href="path/to/ie-stylesheet.css" />
<![end if]-->IE版本高于或等于IE 7
<!--[if gte ie 7]>
<link rel="stylesheet" type="text/css" href="path/to/ie-stylesheet.css" />
<![end if]-->IE版本低于8
<!--[if lt ie 8]>
<link rel="stylesheet" type="text/css" href="path/to/ie-stylesheet.css" />
<![end if]-->IE版本小于或等于8
<!--[if lte ie]>
<link rel="stylesheet" type="text/css" href="path/to/ie-stylesheet.css" />
<![end if]-->发布于 2011-01-11 19:08:29
这就是IE Conditional Comments的作用:)
要使某些样式仅在IE中工作,您可以执行以下操作:
<!--[if IE]>
<style type="text/css">
/* styles for the IE */
</style>
<![endif]-->或者,您可以为IE创建一个单独的样式表,并像这样导入:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="iecss.css" />
<![endif]-->条件注释只能在Windows上的资源管理器中使用,因此非常适合于给出仅适用于Windows上的资源管理器的特殊说明。从Explorer5开始支持它们,甚至可以区分5.0、5.5和6.0。
https://stackoverflow.com/questions/4656918
复制相似问题