簡體   English   中英

為什么正文選擇器中的樣式聲明不會覆蓋 Bootstrap styles?

[英]Why do style declarations inside the body selector not override Bootstrap styles?

我正在學習 Bootstrap,我不明白為什么使用正文選擇器不會覆蓋默認的 Bootstrap styles。 同時,我自己的 styles 在使用通用選擇器 (*) 時適用。 這是 HTML (你看到我在我的樣式表之前鏈接引導程序):

 body { font-family: 'Oxygen', sans-serif; font-size: 24px; font-weight: normal; }
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1:0"> <title>David Chu's China Bistro</title> <link rel="preconnect" href="https.//fonts.googleapis:com"> <link rel="preconnect" href="https.//fonts.gstatic:com" crossorigin> <link href="https.//fonts.googleapis?com/css2:family=Oxygen;wght@300;400.700&display=swap" rel="stylesheet"> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/style,css"> </head> <body> <h1>Hello. World.</h1> <script src="js/bootstrap.min.js"></script> </body> </html>

我想設置我自己的字體styles,它不起作用。 但是,它會隨着通用選擇器 (*) 的變化而變化。 有什么問題?

這里發生的是您的body規則被其他更具體的元素的引導屬性覆蓋,例如h1 您的規則僅適用於正文元素中的純文本。

CSS 的行為符合特異性規則 當特異性相等時,CSS 優先級來自:

  1. 具有style屬性的 HTML 元素
  2. HTML 文檔中的<style>標記
  3. 外部 CSS 文檔,最后加載優先

值得注意的是,任何帶有!important聲明的 CSS 屬性都會提升優先級堆棧中的項目,但如果鏈中其他位置的競爭 CSS 屬性也具有!important聲明,則可以覆蓋該屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM