CSS技巧(三):CSS經常忘記兩個簡寫

來源:互聯網
上載者:User

標籤:style   blog   http   color   ar   使用   strong   sp   div   

盒子大小

這裡主要用於兩個屬性:margin和padding,我們以margin為例,padding與之相同。盒子有上下左右四個方向,每個方向都有個外邊距:

縮寫的順序是上->右->下->左。順時針的方向。相對的邊的值相同,則可以省掉:

margin:1px;//四個方向的邊距相同,等同於margin:1px 1px 1px 1px;margin:1px 2px;//上下邊距都為1px,左右邊距均為2px,等同於margin:1px 2px 1px 2pxmargin:1px 2px 3px;//右邊距和左邊距相同,等同於margin:1px 2px 3px 2px;margin:1px 2px 1px 3px;//注意,這裡雖然上下邊距都為1px,但是這裡不能縮寫。

 

font
font簡寫也是使用最多的一個,它也是書寫高效的CSS的方法之一。

font包含以下屬性:

font-style: normal || italic || oblique;font-variant:normal || small-caps;font-weight: normal || bold || bolder || || lighter || (100-900);font-size: (number+unit) || (xx-small - xx-large);line-height: normal || (number+unit);font-family:name,"more names";

 

font的各個屬性也都有預設值,記住這些預設值相對來說比較重要:

font-style: normal;font-variant:normal;font-weight: normal;font-size: inherit;line-height: normal;font-family:inherit;

事實上,font的簡寫是這些簡寫中最需要小心的一個,稍有疏忽就會造成一些意想不到的後果,所以,很多人並不贊成使用font縮寫。

不過這裡正好有個小手冊,相信會讓你更好的理解font的簡寫:

 

參考:

常用CCS文法總潔

前端觀察

CSS技巧(三):CSS經常忘記兩個簡寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.