前面有人提到重點了, 我加點料......
我想原作者是強調 "Explicitly" re-defined style rule,
[解釋內容]
建議
define rules only once for a certain selector,
and group all rules belonging to that selector.
就是把同一個 selector 的所有 rules 寫在同一個區塊, 而不要穿插在各處,
因為
In CSS stylesheets, order is important.
f you define a rule and then you re-define the same rule,
the last definition is used.
就是說由於 CSS 編寫的 order 關係到 cascading,
穿插在各處可能會考驗寫作者的記憶力, 導致 cascading 結果和預期不符的 error
為了要 avoid this kind of error, 所以說最好是 "Explicitly" re-defined style rule
[例子]
請把它想像成個幾百行的文件,兩個 .redtext 之間隔了二頁,
代碼:
#section { font-weight: bold; }
.redtext { color: red; }
/* other rules */
/* other rules */
/* other rules */
.redtext { font-weight: normal; }
<div id="section">
This is bold,
<span class="redtext"> this is normal and red,</span>
and bold again
</div>
他建議改為
代碼:
#section { font-weight: bold; }
.redtext { color: red; font-weight: normal; }
/* other rules */
/* other rules */
/* other rules */
<div id="section">
This is bold,
<span class="redtext"> this is normal and red,</span>
and bold again
</div>
這樣可以明白地 (Explicitly) 知道
.redtext 不繼承或說重新定義了 (re-defined)
#section 的樣式規則 (style rule) - "font-weight: bold"
寫在一起才不會忘了後面的 .redtext { font-weight: normal; },
而誤以為 <span class="redtext"></span> 內也應該是 bold,
但結果和預期不同
結論--
原作者的解釋和例子不合, 解釋內容說的 cascading order, 但例子卻是在說 inheritance,
此外,標題的 re- 也沒必要, 說重新定義有點奇怪, 直接說明白地定義樣式規則就好了
總而言之一句話, 原文所要表達的就是"寫在一起比較不會混亂"
報告完畢