CSS 2.1 快速導覽 - 文字行高 line-height

line-height 性質 (property) 為 CSS 中用來設定文字的行高,可用數字或百分比進行設定。



舉例如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
.example1 {
    line-height: 1px;
}
 
.example2 {
    line-height: 2px;
}
 
.example3 {
    line-height: 3px;
}
 
.example4 {
    line-height: 4px;
}
 
.example5 {
    line-height: 5px;
}
 
.example6 {
    line-height: 6px;
}
 
.example7 {
    line-height: 7em;
}
 
.example8 {
    line-height: 25%;
}
 
.example9 {
    line-height: 50%;
}
 
/* 《程式語言教學誌》的範例程式
    檔名:text10.css
    功能:示範 CSS 2.1 樣式表的使用
    作者:張凱慶
    時間:西元 2011 年 7 月 */


我們以下面的 HTML 文件載入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css"
      href="text12.css">
</head>
<body>
<div class="example1">
Free your mind.
</div>
<div class="example2">
Free your mind.
</div>
<div class="example3">
Free your mind.
</div>
<div class="example4">
Free your mind.
</div>
<div class="example5">
Free your mind.
</div>
<div class="example6">
Free your mind.
</div>
<div class="example7">
Free your mind.
</div>
<div class="example8">
Free your mind.
</div>
<div class="example9">
Free your mind.
</div>
</body>
</html>
 
<!-- 《程式語言教學誌》的範例程式
     檔名:text12.html
     功能:示範 CSS 2.1 樣式表的使用
     作者:張凱慶
     時間:西元 2011 年 7 月 -->


瀏覽器 (broswer) 開啟如下



前面數個 <div> 元素的行高設定過小,所以產生都擠在一起的視覺效果。


中英文術語對照
性質property
瀏覽器broswer


您可以繼續參考

JavaScript 範例

文字相關


相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁


參考資料
http://www.w3.org/TR/CSS21/visudet.html
https://developer.mozilla.org/en/CSS/line-height

沒有留言: