整理了一下自己寫 CSS 時的屬性順序,貼出來參考。排列規則很簡單:由上而下、由左而右。同一行內的多個屬性以 || 分隔,代表可並列且順序可互換。
display || visibility list-style : list-style-type || list-style-position || list-style-image position top || right || bottom || left z-index clear float
width max-width || min-width height max-height || min-height overflow || clip margin : margin-top || margin-right || margin-bottom || margin-left padding : padding-top || padding-right || padding-bottom || padding-left outline : outline-color || outline-style || outline-width border background : background-color || background-image || background-repeat || background-attachment || background-position
color font : font-style || font-variant || font-weight || font-size || line-height || font-family font : caption | icon | menu | message-box | small-caption | status-bar text-overflow text-align text-indent line-height white-space vertical-align cursor
這套順序的核心邏輯是:先決定元素「是什麼、在哪裡」(顯示方式、定位、層級、浮動),再處理「有多大、怎麼排」(尺寸、間距、邊框、背景),最後才是「看起來如何」(色彩、字型、文字對齊與游標)。實際使用時可依團隊習慣微調,重點是全組採用同一套規則,讓任何人接手都能快速定位屬性。