pay*_*ing 1 html css conditional
我正在尝试使用IE特定的条件语句来根据浏览器类型更改类设置.我觉得他们可以做到这一点,但我似乎无法让它发挥作用.
下面是一个简单的例子,如果浏览器是IE,文本应该是蓝色,否则文本应该保持红色.
"浏览器是IE"在机身上的声明工作正常,如果我打开firefox它不存在,Internet Explorer ..它是.
我究竟做错了什么?
<html>
<head>
<style type="text/css">
.class{color:red;}
<!--[if IE]>
.class{color:blue;}
<![endif]-->
</head>
</style>
<body>
<!--[if IE]>
This browser is IE
<![endif]-->
<p class="class">Color changing text based on browser</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
首先你的代码不工作-你应该有CSS读.color不.class
其次条件语句在css中不起作用.因此,编写代码使得条件是围绕IE特定样式.
<html>
<head>
<style type="text/css">
.color{ color:red; }
</style>
<!--[if IE]>
<style type="text/css">
.color{ color:blue; }
</style>
<![endif]-->
</head>
<body>
<!--[if IE]>
This browser is IE
<![endif]-->
<p class="color">Color changing text based on browser</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)