根据浏览器显示不同的颜色

时间:2017-02-15 12:31:56

标签: html css

我有一个运动问题:

写一个CSS片段,在旧版浏览器中显示蓝色的段落,在较新的浏览器中显示为红色,在IE6中显示为绿色,在IE7中显示为黑色

我开始认为这是一个技巧问题,因为经过大量谷歌搜索后,我能找到的唯一条件浏览器代码就是这样的html:

 <!--[if IE]>
    According to the conditional comment this is IE<br />
    <![endif]-->

虽然这对我来说实际上并不起作用,因为vis studio只是将此声明作为评论处理。据我所知,编写一个css片段是不可能的,我是对的吗?

2 个答案:

答案 0 :(得分:1)

我真的不应该给你一个测验的答案......但是

<!--[if IE]>
<div class="ie">
<![endif]-->

<!--[if IE 6]>
<div class="ie6">
<![endif]-->

<!--[if IE 7]>
<div class="ie7">
<![endif]-->

<!--[if IE 8]>
<div class="ie8">
<![endif]-->

<!--[if IE 9]>
<div class="ie9">
<![endif]-->

<!--[if gte IE 8]>
<div class="ie8plus">
<![endif]-->

<!--[if lt IE 9]>
<div class="ie9lower">
<![endif]-->

<!--[if !IE]> -->
<div class="not-ie">
<!-- <![endif]-->

</div>

我会把CSS规则留给你;)

答案 1 :(得分:1)

对任何版本的IE使用不同的css文件

<!--[if !IE]--><link href="styles.css" rel="stylesheet" media="all" /><!--[endif]-->
<!--[if IE 6]><link href="ie6.css" rel="stylesheet" media="all" /><![endif]-->
<!--[if IE 7]><link href="ie7.css" rel="stylesheet" media="all" /><![endif]-->
<!--[if IE 8]><link href="ie8.css" rel="stylesheet" media="all" /><![endif]-->
相关问题