CSS3优先顺序的浏览器 [英] CSS3 priority order for browsers

查看:131
本文介绍了CSS3优先顺序的浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS3样式表的优先顺序是什么?

What's the priority order on a CSS3 style sheet?

我的意思是,假设我们对CSS中的相同内容有不同的设置。

I mean, imagine that we have different settings for the same content inside the CSS. Which one will the browser choose and apply?

这与CSS中的代码位置有关吗?

Is this something related to the position of the code inside the CSS? I mean from top to bottom?

推荐答案

浏览器加载CSS标签的顺序将决定采用哪个值。

The order that the Browser loads the CSS tags in will determine which value is taken.

因此,如果您将CSS文件放在文档的末尾,那么它们将逐个应用,覆盖任何现有的重复选择器

So, if you put the CSS files at the end of your document, then they will be applies in order, one by one, overwriting any existing duplicate selectors that they come across.

示例:

#myDiv { 
background-color: blue;
width: 300px;
height: 200px;
}


#myDiv { 
background-color: red;
width: 300px;
height: 200px;
}

<div id="myDiv">
Demo
</div>

这篇关于CSS3优先顺序的浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆