久久久久久久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在线观看免费 | 91看片网 | 亚洲色欲色欲www | 国产区高清| 成人在线精品视频 | 中文字幕1区2区3区 日韩在线视频免费观看 | 美女黄色在线观看 | 国产精品免费一区二区三区 | 中文字幕在线视频精品 | 亚洲精品www | 欧美一区二| 亚洲一区日韩 | 国产精品久久久久久久久久了 | 中文字幕一区二区三区四区 | 国产综合网址 | 日本一区二区高清不卡 | 日本一区二区在线视频 | 神马久久春色视频 | 日本精品一区二区三区视频 | 日本天天操 | 国产精品无码专区在线观看 | 亚洲三区视频 | 亚洲国产精品一区二区www | 亚洲精品电影网在线观看 | 一级片成人 | 我想看国产一级毛片 | 中文字幕亚洲区一区二 | 亚洲欧美国产毛片在线 | 四虎免费视频 | 午夜视频一区二区 | 国产黄色网址在线观看 | 在线观看免费黄色片 | 一区二区不卡 | 欧美日韩成人影院 | 欧美日韩综合 | 亚洲成人三级 | 亚洲欧美日韩电影 | 国产精品久久久久久久久久免费看 | 日韩一区二区黄色片 |