gpt4 book ai didi

css - 基本的 CSS 问题

转载 作者:行者123 更新时间:2023-12-05 00:27:22 25 4
gpt4 key购买 nike

我想这对您来说相当简单,但我无法理解它。我撕掉了重要的部分。我在 #content 中有文字,所以我无法更改它,我不想使用 !important 标签。css 按照它在我的 css 文件中的顺序呈现。

为什么“#content h2 a, #content h2 a:visited”会覆盖 .post-header h2 a?

<html>
<head>
.....
</head>
<div id="content">
.....
<div class="post-header">
<a href="#">my text</a>
</div>
</div>
</html>


#content h2 a, #content h2 a:visited {
font-family:"arial black","lucida console",sans-serif;
}

.post-header h2 a {
font-family:Arial,sans-serif;
}

/乔尔

最佳答案

首先,浏览器检查 cascading order .由于声明都针对相同的媒体、重要性和来源,因此规则按特殊性排序。

接下来,浏览器计算the selector's specificity , 和(这是你的问题的重要部分)Id 选择器比类选择器优先级更高:

A selector's specificity is calculated as follows:

  • count 1 if the declaration is from is a 'style' attribute rather than a rule with a selector, 0 otherwise (= a) (In HTML, values of an element's "style" attribute are style sheet rules. These rules have no selectors, so a=1, b=0, c=0, and d=0.)
  • count the number of ID attributes in the selector (= b)
  • count the number of other attributes and pseudo-classes in the selector (= c)
  • count the number of element names and pseudo-elements in the selector (= d)

The specificity is based only on the form of the selector. In particular, a selector of the form "[id=p33]" is counted as an attribute selector (a=0, b=0, c=1, d=0), even if the id attribute is defined as an "ID" in the source document's DTD.

Concatenating the four numbers a-b-c-d (in a number system with a large base) gives the specificity.

关于css - 基本的 CSS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2585559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com