css中提升优先级属性!important的用法总结
发布时间:2016-12-27 来源:查字典编辑
摘要:无标题文档#boxdiv{color:red;}.important_false{color:blue;}.important_true{c...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
<>
<>
#box div {
color:red;
}
.important_false {
color:blue;
}
.important_true {
color:blue !important;
}
#box2 {
background-color: #cccccc !important;
background-color: #000000;
}
<>
#idColor {
color:gray;
}
</style>
</head>
<body>
<div id="box">
<div id="idColor">这一行末使用important。class的优先级小于id的优先级。IE7是红色,firefox是蓝色。</div>
<div >这一行使用了important</div>
</div>
<div id="box2"> 在不同的浏览器下,这行字的色应该不同!IE7,Firefox是红色。IE6是蓝色</div>
</body>
</html>