2010-01-14 77 views

回答

2

個人我嘗試組屬性或多或少像這樣:

  • 盒模型(高度,寬度,填充,餘量...)
  • 定位
  • 字體相關(字體家庭,字體重量等)
  • 顏色和背景圖片

有沒有真正的利益做事情就這樣,我只是覺得這合理合乎邏輯且易於遵循。

簡單的例子(帶註釋來說明):

#selector{ 
    /* box */ 
    width: 300px; 
    margin: 15px 0 30px; 
    padding: 5px; 
    border: 1px solid #333; 

    /* position */ 
    float: left; 
    display: inline; 

    /* font */ 
    font-family: 'Lucida Grande', 'BitStream Vera Sans', Verdana, sans-serif; 
    font-weight: normal; 
    font-size: 14px; 

    /* colour */ 
    color: #000; 
    background: #ddd; 
} 

值得注意我通常保持組合選擇上一條線(即在同一行的所有箱相關的選擇,等等)

0

查看Andy Ford's post詳細說明了他訂購CSS屬性的方法。他在主題上以a nice round-up of further reading around the internet結束。

+1

我的博客已不在,但帖子在Wayback Machine上https://web.archive.org/web/20130227044124/http://fordinteractive.com/2009/02/order-of-the- day-css-properties/Bootstrap聯合創始人Mark Otto也有一個非常相關的帖子:http://markdotto.com/2011/11/29/css-property-order/ – 2015-06-10 19:42:25