- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在阅读 Adam Freeman 的“HTML5 权威指南”,并且有一个关于 CSS 特异性的问题。他给出了以下示例:
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
<style type="text/css">
a {
color: black;
}
a.myclass {
color: white;
background: grey;
}
</style>
</head>
<body>
<a href="http://apress.com">Visit the Apress website</a>
<p>I like <span>apples</span> and oranges.</p>
<a class="myclass" href="http://w3c.org">Visit the W3C website</a>
</body>
</html>
并指出:
In this case, the selector a.myclass includes a class attribute, which means that the specificity of the style is 0-1-0 (0 id values + 1 other attributes + 0 element names). The other style has a specificity of 0-0-0 (that is, it contains no id values, other attributes or element names).
我原以为“a.myclass”选择器的特异性得分为 0-1-1,因为它包括类和元素。同样,我希望“a”选择器的得分为 0-0-1。将这两个选择器输入到这个 CSS Specificity Calculator确实产生了我期望的结果。 (除了这个计算器在分数中包含内联样式)
谁能解释 Adam 的评论,或者我应该将其报告为勘误表?
最佳答案
你是对的。 a.myclass
选择器的特异性得分为 0-1-1
。 a
是类型选择器,必须以 1 计分。
请检查 w3.org 特异性示例:
* /* a=0 b=0 c=0 -> specificity = 0 */
LI /* a=0 b=0 c=1 -> specificity = 1 */
UL LI /* a=0 b=0 c=2 -> specificity = 2 */
UL OL+LI /* a=0 b=0 c=3 -> specificity = 3 */
H1 + *[REL=up] /* a=0 b=1 c=1 -> specificity = 11 */
UL OL LI.red /* a=0 b=1 c=3 -> specificity = 13 */
LI.red.level /* a=0 b=2 c=1 -> specificity = 21 */
#x34y /* a=1 b=0 c=0 -> specificity = 100 */
#s12:not(FOO) /* a=1 b=0 c=1 -> specificity = 101 */
关于html - Adam Freeman 书中的 CSS 特异性查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32085024/
我正在尝试在 delphi 下创建一个名为 TRange 的通用类。这个想法是,它可以是整数范围或单精度范围或 double 范围等... TRange 对象包含一些 T 类型的变量(maxValue
我对 Javascript 非常陌生,正在寻找一种方法让我的代码仅响应列表中单击的项目。 (完整的 JSFiddle 在这里: http://jsfiddle.net/5cjPF/ ,尽管由于某种原因
我遇到了一个问题,我无法获得使某些代码正常工作所需的特异性级别。我有一个 我想为其制作 的背景悬停在带有花哨的小滑入动画上时会发生变化。 我设法使用 linear-gradient 让它工作得很好用
我在使用一些自定义的 960.gs 类时遇到了一些困难。当我使用子容器时出现问题,子容器的列只是继承主容器列规则的宽度。 在我看来,内部单元格 (foo + bar) 应该是绿色的。这意味着他们应该获
我将第 3 方组件附加到 div 元素(容器)。此 div 元素位于 from 内,表单具有 cssform 类。我使用的主要 CSS 表包含定义: .cssform div { max-wi
我在一个 HTML 元素上有两个 CSS 类:.c-headline-1和 .c-hero__headline .在我的外部样式表中,我使用 .c-headline-1在内部样式表 ( ) 中,我使
我在这里对我的样式表感到非常困惑。我的工作表中有很多特定的链接样式,由于某种原因,当我使用 Chrome 开发工具或 Firebug 检查页面时,其中一个随机样式会被其他样式覆盖。在摆弄 !impor
我正在重新设计我的博客,考虑到响应式网页设计和“移动优先”方法 - 简而言之,我正在尝试使用最小宽度来避免任何类型的复制或 css.. 没有显示:无等.. 我的问题是,当我确实需要覆盖 CSS 值时,
我一直在阅读有关特异性的内容,坦率地说,我很惊讶我之前没有正确了解这一点,因为我亲眼目睹了如果 CSS 声明错误,特异性可能会带来的问题方式。 所以,我对这个主题做了一些研究,现在我了解了计算特异性的
我一直在阅读特异性,坦率地说,令我惊讶的是我之前没有正确地了解这一点,因为我亲眼目睹了如果 CSS 声明错误,特异性会带来的问题方式。 因此,我一直在对该主题进行一些研究,现在我了解了计算特异性的规则
我想使用以下内容来定位我的 div 中最后一个 ul 的最后一个链接 (a)。所以这就是我想到的: #menu ul:last-child li a { /*.....*/ } 我无法手
为什么这两个结果不等价?第一个显示绿色行,而第二个不显示。唯一不同的是html c 还有,nth-child选择器的特殊性是什么? Stripe Test
我正在制作响应式电子邮件模板,并希望申请 display: block !important至 2 元素,以便从 2 列布局变为 1 列布局。我正在使用以下选择器: td[class="mainArt
我在大学计算机科学系的 Web 开发课上,老师问类(class):“为什么类选择器规则应用在标签选择器规则之上(参见示例代码)?”。我回答说这是因为 CSS 的特殊性,我被告知我错了。他想要的答案是因
这对我来说是一个学习练习,所以在此先感谢您没有告诉我为什么我不想执行以下操作。我不想做,我想明白。 给定以下 CSS: input[type="file"]:focus, input[type="ra
我正在编写一堆 PHP 类,它们将用于创建 Wordpress 插件,但也可以在任何其他环境中使用。在自己测试我的脚本之后,一切似乎都很好,但是当我为它创建一个 WP 插件时,出现了我预见到的 CSS
我简单看了下CSS3 Selectors spec但找不到任何解决这个问题的方法。此外,我没想到当您移动 CSS 声明时结果会发生变化,但它确实发生了变化。任何帮助都会很棒。 div.green_co
假设我有以下 CSS: .InfoTable-main-table tbody tr td:before{ background: #222; color: #fff; c
因 CSS 存在特殊性问题而发疯。HTML。
http://jsfiddle.net/DkAqZ/9 HTML default black text default red link #inner gr
我是一名优秀的程序员,十分优秀!