標籤:
一、字型樣式
1、font-style:設定或檢索對象中的文本字型樣式。
取值:
normal:指定文本字型樣式為正常的字型
italic:指定文本字型樣式為斜體。對於沒有斜體變數的特殊字型,將應用oblique
oblique:指定文本字型樣式為傾斜的字型
2、font-variant:設定或檢索對象中的文本是否為小型的大寫字母。
取值:
normal:正常的字型
-
small-caps:小型的大寫字母字型
-
3、font-weight:設定或檢索對象中的文本字型的粗細。
-
取值:
-
normal:正常的字型。相當於number為400
-
bold:粗體。相當於number為700。
-
bolder:特粗體。也相當於strong和b對象的作用
-
lighter:細體
-
integer:用數字表示文本字型粗細。取值範圍:100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
4、font-size:設定或檢索對象中的字型尺寸。
取值:
absolute-size:根據對象字型進行調節。選擇性參數值:xx-small | x-small | small | medium | large | x-large | xx-large
relative-size:相對於父對像中字型尺寸進行相對調節。使用成比例的em單位計算。選擇性參數值:smaller | larger
length:用長度值指定文字大小。不允許負值。
percentage:用百分比指定文字大小。其百分比取值是基於父物件中字型的尺寸。不允許負值。
5、font-family:設定或檢索用於對象中文本的字型名稱序列。
取值:
family-name:字型名稱。可以有多個值,以逗號隔開。瀏覽器以先後順序依次使用字型。
generic-family:字型序列名稱。
6、font-stretch:設定或檢索對象中的文字是否橫向展開變形。
取值:
ultra-condensed:比正常文字寬度窄4個基數。
extra-condensed:比正常文字寬度窄3個基數。
condensed:比正常文字寬度窄2個基數。
semi-condensed:比正常文字寬度窄1個基數。
normal:正常文字寬度
semi-expanded:比正常文字寬度寬1個基數。
expanded:比正常文字寬度寬2個基數。
extra-expanded:比正常文字寬度寬3個基數。
ultra-expanded:比正常文字寬度寬4個基數。
註:也可以直接用font:[ [ <font-style> || <font-variant> || <font-weight> ]? <font-size> [ / <line-height> ]? <font-family> ] 簡寫的方式。
下面舉個綜合以上屬性的例子:
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> #p1{ font-family: "微軟雅黑"; font-size: 15px; font-style: italic; font-stretch:extra-condensed; font-weight: bold; font-variant: normal; }
/* #p1{
font:italic normal bold 15px "微軟雅黑";
}*/
</style> </head> <body> <p id="p1">翦翦風,鴛鴦燈。星月無眠,鵲橋築夢。</p> </body></html>
效果如下:
翦翦風,鴛鴦燈。星月無眠,鵲橋築夢。
二、元素樣式
1、寬度
width:auto|length
例:p{ width:100px;}
div{width:50%;}
height:auto|length;
例:p{height:200px;}
div{height:50%;}
3、外邊距
margin:auto|length
取值:
margin-top: 設定上邊的外邊距
margin-right: 設定右邊的外邊距
margin-bottom: 設定下邊的外邊距
margin-left: 設定左邊的外邊距
縮寫形式:
margin:上邊距 右邊距 下邊距 左邊距
margin:上下邊距 左右邊距
margin:上邊距 左右邊距 下邊距
例子如下:
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> #div1{ width:200px; height: 100px; background:pink; } #div2{ width: 110px; height: 80px; margin-top:20px; margin-right: 20px; margin-bottom: 30px; margin-left: 40px; background: blue; } </style> </head> <body> <div id="div1"> <div id ="div2"> 我是裡邊的內容。 </div> </div> </body></html>我是裡邊的內容。
4、內邊距
padding:auto|length
取值:
padding-top: 設定上邊的內邊距
padding-right: 設定右邊的內邊距
padding-bottom: 設定下邊的內邊距
padding-left: 設定左邊的內邊距
縮寫形式:
padding:上邊距 右邊距 下邊距 左邊距
padding:上下邊距 左右邊距
padding:上邊距 左右邊距 下邊距
例子如下:
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> #div3{ width: 100px; height: 100px; padding-top: 20px; padding-right: 30px; padding-bottom: 30px; padding-left: 10px; background-color: #0000FF; } </style> </head> <body> <div id="div3"> 我是裡面的內容 </div> </body></html>我是裡面的內容
CSS常用樣式(一)