CSS 的重要性顺序如下:
1 - 单一声明
body {
background: red;
}
2 - 第一个之下的任何声明
body {
background-color: red;
}
body {
background-color: blue; /* (This will be applied) */
}
/* I'm overwriting my background, so it should be blue now */
标题上的位置也会影响。
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
我的 style.css 覆盖了 bootstripe 文件中的任何内容,在本例中,但请参阅下一个主题以了解例外情况
3 - 更具体的声明
.container button.awesome-button {
font-size: 14px; /* (This will be applied) */
}
.awesome-button{
font-size: 10px;
}
由于第一个声明非常具体,因此将考虑该声明。这就像告诉'嘿,任何.awesome-button 都应该是10px,然后指出“任何button 在.container 下并且具有.awesome-button 类应该是14px。所以你的CSS 应该尊重最具体和精确的坐标.
4 - CSS 作为属性
<style>
.blue{
color:blue;
}
</style>
<div class="blue" style="color: red">The color of this div will be red, no matter the class</div>
直接在 HTML 上设置样式将优先于样式表上的任何内容。
5 - 带有!important 的元素(如果有更多!important 元素,则为具体内容)
.awesome-button {
font-size: 14px !important; /* (This will be applied) */
}
.awesome-button{
font-size: 10px;
}
任何带有!important 的东西,啊……更重要,所以你的CSS 会理解这一点。但是,如果有更多的!important 规则,其他规则将应用在重要元素内。
当心:使用!important 应谨慎使用,在某些情况下应作为最后的资源。
因此,在您的情况下,只需将所有媒体查询放在“正常”css 之后,如下所示:
.right {
text-align: right;
}
.jane {
width: 100%;
font-size: 70pt;
}
.ninja {
width: 100%;
font-size: 25pt;
}
@media screen and (max-width: 450px) {
.box_url {
font-size: 12pt;
}
.box_heading {
font-size: 13pt;
}
.right {
text-align: left;
}
.jane {
font-size: 10pt;
}
.ninja {
font-size: 12pt;
}
}