定义颜色属性的多个类的优先级由声明顺序而不是规范顺序设置 [英] Precedence of multiple classes defining color property being set by declaration order rather than specification order

查看:326
本文介绍了定义颜色属性的多个类的优先级由声明顺序而不是规范顺序设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定两个相等的特异性定义颜色属性的类,我认为元素类属性中列出的最后一个类将优先。

Given two classes of equal specificity defining the color property I thought the last class listed in the element class attribute would take precedence.

http://htmlhelp.com/reference/css/ structure.html


为了方便起见,

Order of Specification To make it easy, when two rules have the same weight, the last rule specified wins.

在以下真空代码示例中,定义类规则集的顺序确定优先级。这里,最后一个或最近的类规则集定义优先。

In the following vacuum code example the order in which the class rule set is defined determines precedence. Here the last, or most recent, class rule set definition takes precedence.

<style>
    .makeBlue {color: blue;}
    .makeGreen {color:green;}
</style>
<div>
    <p class="makeGreen makeBlue">makeGreen makeBlue</p>
    <p class="makeBlue makeGreen">makeBlue makeGreen</p>
</div>

输出文字为绿色。

如果我交换类声明的顺序,并声明.makeGreen第一

If I swap the order of class declaration, and declare .makeGreen first

<style>
    .makeGreen {color:green;}
    .makeBlue {color: blue;}        
</style>
<div>
    <p class="makeGreen makeBlue">makeGreen makeBlue</p>
    <p class="makeBlue makeGreen">makeBlue makeGreen</p>
</div>

输出文字为蓝色。

我从来没有注意到这一点。 我认为最后一个类在元素类属性中优先。

I've never noticed this before. edit I thought edit the last class listed in the element class attribute takes precedence.

/ em>
澄清 - >
我有时想到一个元素作为宠物,我们说一只狗。我看到添加一个类到元素的class属性作为发出狗的命令。如果我告诉它坐下,然后告诉它躺下,我期望狗躺下。我不期望狗只保持坐,因为我教它如何坐(最近比我)教它如何躺下。

edit To clarify --> I sometimes think of an element as a pet, let's say a dog. I see adding a class to the element's class attribute as issuing the dog a command. If I tell it to sit, and later tell it lie down, I expect the dog to lie down. I do not expect the dog to remain sitting simply because I taught it how to sit after (more recently than) I taught it how to lie down.

所以...两个问题。


  1. 成为? 已回答

  2. 如果是这样,为什么?我无法看到必须挖掘类
    声明以确定哪个是在另一个之前声明的优势。

非常感谢!

推荐答案

在元素上指定类的顺序是不相关的。这是你在你的风格声明中定义它们的顺序。您发布的报价是指在样式声明中,而不是在元素上列出的类别。

The order of the classes as you specify them on the elements is irrelevant. It's the order that you define them in your style declarations that matters. The quote you posted means in the style declarations, not the order the classes are listed on the elements.

这篇关于定义颜色属性的多个类的优先级由声明顺序而不是规范顺序设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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