將兩個或更多 css 規則應用于同一文本時,這些規則可能會發生沖突并產生意外的結果。瀏覽器按以下方式應用 css 規則:
class 屬性應用的規則)中的屬性將覆蓋 html 標簽樣式中的屬性。 在下面的示例中,為 h1 定義的樣式可以指定所有 h1 段落的字體、大小和顏色,但應用于該段落的自定義 css 規則 .blue 將覆蓋 h1 樣式中的顏色設置。另一個自定義 css 規則 .red 將覆蓋 .blue,因為它位于 .blue 樣式的內部。
<h1><span class="blue">this paragraph is controlled by the .blue custom style and h1html tag style.<span class="red">except this sentence is controlled by the .red style.</span>now we're back to the .blue style.</span></h1>
新聞熱點
疑難解答