萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Div CSS 教學

CSS 縮寫屬性完整指南:顏色、盒模型、邊框、背景、字體與列表的簡寫語法

1. 顏色縮寫

十六進制每兩位相同可縮寫:

#000000 → #000
#336699 → #369

2. 盒模型縮寫

順時針:上 → 右 → 下 → 左

margin: 1em;           /* 四邊同值 */
margin: 1em 2em;       /* 上下 1em、左右 2em */
margin: 1em 2em 3em;   /* 上 1em、左右 2em、下 3em */
margin: 1em 2em 3em 4em; /* 上右下左 */

適用於 margin、padding、border-width。

3. 邊框 Border

border-width: 1px;
border-style: solid;
border-color: #000;
/* 縮寫 */
border: 1px solid #000; /* 順序:width style color */

4. 背景 Background

background-color: #f00;
background-image: url(bg.gif);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: 0 0;
/* 縮寫 */
background: #f00 url(bg.gif) no-repeat fixed 0 0;
/* 順序:color image repeat attachment position */

省略值採預設:transparent / none / repeat / scroll / 0% 0%。

5. 字體 Font

font-style: italic;
font-variant: small-caps;
font-weight: bold;
font-size: 1em;
line-height: 140%;
font-family: "Lucida Grande", sans-serif;
/* 縮寫:至少需 size + family */
font: italic small-caps bold 1em/140% "Lucida Grande", sans-serif;

6. 列表 List

list-style-type: square;
list-style-position: inside;
list-style-image: url(img.gif);
/* 縮寫 */
list-style: square inside url(img.gif);

取消樣式:list-style: none;

copyright © 萬盛學電腦網 all rights reserved