久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CSS 特性如何決定應用哪些樣式?

How does CSS specificity decide which styles to apply?(CSS 特性如何決定應用哪些樣式?)
本文介紹了CSS 特性如何決定應用哪些樣式?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

CSS 如何確定何時將一種樣式應用于另一種樣式?

How does CSS determine when to apply one style over another?

我已經閱讀了幾次W3 CSS3 選擇器文檔,并且已經幫助我理解了如何在 jQuery 中更好地使用 CSS 選擇器,但它并沒有真正幫助我理解何時將一個 CSS 規則應用于另一個.

I have been through the W3 CSS3 selectors document a few times, and that has helped me understand how to better use CSS selectors in jQuery, but it has not really helped me understand when one CSS rule will be applied over another.

我有以下 HTML:

<div class='item'>
    <a>Link 1</a>
    <a class='special'>Link 2</a>
</div>

我有以下 CSS:

.item a {
    text-decoration: none;
    color: black;
    font-weight: bold;
    font-size: 1em;
}

.special {
    text-decoration: underline;
    color: red;
    font-weight: normal;
    font-size: 2em;
}

鑒于上述情況,鏈接 1 和鏈接 2 的樣式將相同,由 .item a CSS 確定.為什么與 .special 關聯的樣式不優先鏈接 2?

Given the above, both Link 1 and Link 2 will be styled the same, as determined by the .item a CSS. Why does the style associated with .special not take precedence for Link 2?

顯然,我可以像這樣繞過它:

Obviously, I can get around it like this:

.special {
    text-decoration: underline !important;
    color: red !important;
    font-weight: normal !important;
    font-size: 1em !important;
}

但是,由于缺乏理解,我覺得這是我必須散布的技巧.

But, I feel like that is a hack that I have to sprinkle in due to my lack of understanding.

推薦答案

它基于 IDsclassestags.IDs 具有最高的特異性,然后是 classes 然后是 tags,所以:

It's based on IDs, classes and tags. IDs have the highest specificity, then classes then tags, so:

.item a     == 0 1 1      0 (id) 1 (class=item) 1 (tag=a)
.special    == 0 1 0
#foo        == 1 0 0
#foo .bar a == 1 1 1
#foo #bar   == 2 0 0

以最多者獲勝 :) 如果是平局,則以文件中最后出現的為準.請注意,1 0 0 優于 0 1000 1000

whichever has the most wins :) If it's a tie, whichever one comes last in the document wins. Note that 1 0 0 beats 0 1000 1000

如果您希望 .special 應用,請使其更具體:.item a.special

If you want .special to apply, make it more specific: .item a.special

這篇關于CSS 特性如何決定應用哪些樣式?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Style every third element?(每隔三個元素設置樣式?)
Why shouldn#39;t I use ID selectors in CSS?(為什么我不應該在 CSS 中使用 ID 選擇器?)
What does img[class*=quot;alignquot;] mean in CSS?(CSS 中的 img[class*=“align] 是什么意思?)
CSS: Last element on line(CSS:最后一個元素)
How do I select every other div class element using just CSS (no js)(如何僅使用 CSS(無 js)選擇所有其他 div 類元素)
Tool for checking unused CSS selectors?(檢查未使用的 CSS 選擇器的工具?)
主站蜘蛛池模板: 99成人| 亚洲欧洲日韩 | 日韩免费在线视频 | 亚洲激情第一页 | 少妇黄色 | 国产一区二区久久 | 欧美久久一区二区 | 日韩欧美国产一区二区三区 | 香蕉视频一区二区 | a级免费视频 | 国产成人免费视频网站高清观看视频 | 色综合网站 | 亚洲一区二区三区免费观看 | 色综网 | 精品一区av| 国产精品99久久久久久宅男 | 人人草天天草 | 国产在线精品一区二区三区 | 国产精品区二区三区日本 | 精品在线一区二区三区 | 99热.com| 精品免费国产一区二区三区四区 | 美女中文字幕视频 | 亚洲精品一区在线观看 | 精品免费在线 | 成年人免费看 | 超碰成人在线观看 | 中文字字幕一区二区三区四区五区 | 欧美另类视频 | 一区二区在线免费观看 | 粉嫩一区二区三区四区公司1 | 中文字幕第二区 | 成人在线视频一区 | 在线三级网址 | 91资源在线 | 一区二区三区欧美 | 人人性人人性碰国产 | 91精产国品一二三区 | 日本久久久久久久久 | 伊人精品在线 | 亚洲精品电影网在线观看 |