CSS全域樣式中需要注意的細節

來源:互聯網
上載者:User

在網上看到篇文章講全球很多高手的CSS全域樣式(reset.css),再一次體會到了什麼叫“細節決定成敗”。原文:http://perishablepress.com/press/2007/10/23/a-killer-collection-of-global-css-reset-styles/。 原文是藉著翻譯外掛程式看下來的,大概意思就是講什麼是Css,以及各瀏覽器的css規則的不同,而制定"Css Reset"也是為了相容與統一,正確有效使用"Css Reset"可以在某種程度上節約時間與金錢。我的理解是:CSS reset的意義,不是讓你全部去掉,而是讓各種瀏覽器盡量起點一樣。

牛頓是站在巨人伽利略的肩膀上的,我們也可以這麼做。通過高手們的經 驗,下面兩個細節需要注意。你可以檢查一下你設計網站或者部落格的全域CSS。

不建議用:*{margin:0;padding:0;}

不建議用:* {margin:0;padding:0;}的原因:

  1. *這個感覺不是很好,肯定會影響效率的,儘管不能被肉眼察覺
  2. 效能的消耗是其中一個因素,個人認為會帶來的最大弊端還是對錶單元素的影響。比如checkbox、radio、button之類的標 簽,被定義後在瀏覽器上的顯示很彆扭,需要針對性重寫代碼,消耗的是更多的代碼量和代碼時間。

但是針對一些簡單得頁面,標籤元 素單一且簡單得話,就可以大膽地使用。

建 議使用:img {border:0 none;}

原因是為了相容,因為border邊框屬性在不同瀏覽器中的渲染方式不同。

比 如FF和IE中,僅僅使用img {border:0;}的話,那麼在兩個瀏覽器中border-width都是為0的,但是border-style和border-color兩個屬性 會存在差異。

具體分析結果可以查看:http://blog.linxz.cn/border/

reset.css樣本

那些沒有提到 的標籤如何全域定義就要看具體情況了,比如你的項目中沒有使用的標籤,你何必全域定義呢?

下面的reset.css大部分複製至:YUI。

提 醒:不能盡信高手。沒有最完美的,只有最合適的。

body, div, dl, dt, dd, ul, ol, li,
h1, h2, h3, h4, h5, h6, pre, code,
form, fieldset, legend, input, button,
textarea, p, blockquote, th, td {
    margin: 0;
    padding: 0;
}
fieldset, img {
    border: 0 none;
}
/* remember to define focus styles! */
:focus {
    outline: 0;
}
address, caption, cite, code, dfn,
em, strong, th, var, optgroup {
    font-style: normal;
    font-weight: normal;
}
h1, h2, h3, h4, h5, h6 {
    font-size: 100%;
    font-weight: normal;
}
abbr, acronym {
    border: 0;
    font-variant: normal;
}
input, button, textarea,
select, optgroup, option {
    font-family: inherit;
    font-size: inherit;
    font-style: inherit;
    font-weight: inherit;
}
code, kbd, samp, tt {
    font-size: 100%;
}
/*@purpose To enable resizing for IE */
/*@branch For IE6-Win, IE7-Win */
input, button, textarea, select {
    *font-size: 100%;
}
body {
    line-height: 1.5;
}
ol, ul {
    list-style: none;
}
/* tables still need 'cellspacing="0"' in the markup */
table {
    border-collapse: collapse;
    border-spacing: 0;
}
caption, th {
    text-align: left;
}
sup, sub {
    font-size: 100%;
    vertical-align: baseline;
}
/* remember to highlight anchors and inserts somehow! */
:link, :visited , ins {
    text-decoration: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.