css样式的优先级是在加载css文件的时候就确定下来的,而不是由后来html里class属性位置前后决定的。
例1
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.a {
color: red;
}
.b {
color: blue;
}
</style>
</head>
<body>
<!--red-->
<div class="a">Text</div>
<!--blue-->
<div class="b">Text</div>
<!--blue-->
<div class="a b">Text</div>
<!--blue-->
<div class="b a">Text</div>
</body>
</html>
例2
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.a {
color: red;
}
.b {
color: blue;
}
.a.b {
color: orange;
}
.b.a {
color: green;
}
</style>
</head>
<body>
<!--red-->
<div class="a">Text</div>
<!--blue-->
<div class="b">Text</div>
<!--green-->
<div class="a b">Text</div>
<!--green-->
<div class="b a">Text</div>
</body>
</html>