繼續八卦:CSS Negotiation and a Sanity Saving Shortcut. * { margin: 0; padding: 0 } 的學名是Global White Space Reset. 從原文中可以看出這個方法剛問世時是非常火爆的,并且作者建議一定要先破后立,要將清掃差異和重置默認樣式結合起來,這樣才是正確的做法。
為何Global White Space Reset當初風光一時,如今卻黯然銷魂? * { margin: 0; padding: 0 } 的成功之處在于,管你三七二十八,統統抹平,人人生而平等!然而其失敗之處也正是因為其威力太大,雖然搗了蜂窩得了蜜,卻惹來群蜂追尾,麻煩無限(因為被抹平的樣式,你得再重新設置回來,比如input的padding等)。這就如西漢一代名將韓信哪,是成也蕭何,敗也蕭何!
上面是兩個最有名的CSS Reset方案。但世界永遠是多樣化的,比如Less is more – my choice of Reset CSS. 這和Eric Meyer的期望其實是一致的:不同的應用環境下,應該選擇自己的reset方案,而不是簡單的copy過去。比如Google首頁,在這種特定頁面里,不用就是一種最好的用。
更多眼花繚亂的Reset方案請參看:A Killer Collection of Global CSS Reset Styles. 很標題黨,內容就魚龍混雜了。
最后,隆重揭曉最后一個八卦問題的答案:No CSS Reset. 提倡的核心思想也是Less is more. 原因很簡單, * { margin: 0; padding: 0 } 殺傷力太大,在某些場合下,Eric Meyer的方案殺傷力也還是太大了。有想法并說出來,總是好的。
有反對就會有支持:Why I Like (and Use) Reset CSS. 公說公有理,婆說婆有理,并非所有問題都需要一個確切的答案,有時過程本身,就是追求的結果。
Eric Meyer對No CSS Reset一文的回復:Crafting Ourselves. 讀罷此文,明月松間照,清泉石上流。下面摘錄兩段,做為此八卦閑文的完結:
Because this isn’t a field of straightforward answers and universal solutions. We are often faced with problems that have multiple solutions, none of them perfect. To understand what makes each solution imperfect and to know which of them is the best choice in the situation—that’s knowing your craft. That’s being a craftsman/craftswoman. It’s a never-ending process that is all the more critical precisely because it is never-ending.
…It’s evidence that we continue to challenge ourselves and each other to advance our skills, to keep learning better and better how better to do what we love so much.