簡化常用的CSS屬性代碼,讓你的CSS更精簡清晰

來源:互聯網
上載者:User

簡化CSS屬性代碼,可以讓CSS檔案體積變得更小,讀取速度更快,可維護性更高.

下面分別樣本最常用的一些CSS屬性代碼的簡化方法:

margin
margin-top:1px;
margin-right:1px;
margin-bottom:1px;
margin-left:1px;
代碼簡化為:margin:1px

margin-top:1px;
margin-right:2px;
margin-bottom:1px;
margin-left:2px;
代碼簡化為:margin:1px 2px

margin-top:1px;
margin-right:2px;
margin-bottom:3px;
margin-left:2px;
代碼簡化為:margin:1px 2px 3px

margin-top:1px;
margin-right:2px;
margin-bottom:3px;
margin-left:4px;
代碼簡化為:margin:1px 2px 3px 4px
當屬性值是0的時候單位可以不寫如:0px 直接就寫成0
 
padding
padding的書寫方法和margin一樣,在此就不多敘述
 
border
border-width:1px;
border-style:solid;
border-color:#000000;
代碼簡化為:border:1px solid #000

background
background-color:#CCFFFF;
background-image:url(圖片路徑);
background-repeat:repeat-x;
background-position:5px 4px;
代碼簡化為:background:#CFF url(圖片路徑)  repeat-x 5px 4px

font
font-size:26px;
font-weight:bold;
font-family: “宋體”;
代碼簡化為:font:26px bold “宋體”

color屬性值
color:#000000;
color:#ff0000;
代碼簡化為:color:#000, color:#f00



相關文章

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.