Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 53 期(W3C标准-CSS-语法):样式的顺序 #56

Open
wingmeng opened this issue Jul 7, 2019 · 0 comments
Open

第 53 期(W3C标准-CSS-语法):样式的顺序 #56

wingmeng opened this issue Jul 7, 2019 · 0 comments

Comments

@wingmeng
Copy link
Collaborator

wingmeng commented Jul 7, 2019

有如下代码,请问 HTML 代码中“文本”最终渲染出的颜色分别是?

.red {color: red;}
.blue {color: blue;}
<div class="red blue">文本</div>
<div class="blue red">文本</div>

答案 两个都是蓝色

Why? CSS 的层叠规则里有一条叫做“后来居上原则”,即两个相同权值的样式,如存在相同的声明属性,则后者获胜。
本题的 CSS 样式里,.blue.red 权值相同,且都声明了 color 属性,但 .blue 在样式表中位于 .red 后面的位置,所以当 HTML 中的同一标签同时引用这两个类名时,以 .bluecolor 声明为准,和 HTML 中 className 的先后顺序无关。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant