將兩個或更多 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>
新聞熱點
疑難解答