CSS 2.1 快速導覽 - 高度 height

height 性質 (property) 為 CSS 中用來設定區塊元素 (block element) 的高,也就是垂直方向的長度,除了可用數字或百分比設定外,有以下的關鍵字 (keyword)

  • auto


區塊元素除了高度 height ,還有寬度 width ,通常兩者都需設定,若只有設定其中一個,另一個瀏覽器 (broswer) 通常會自動調整。


.example {
    height: auto;
}

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:block03.css
    功能:示範 CSS 2.1 樣式表的使用 
    作者:張凱慶
    時間:西元 2011 年 7 月 */


我們以下面的 HTML 文件載入
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css" 
      href="block03.css">
</head>
<body>
<img class="example" src="example.jpg">
</body>
</html>

<!-- 《程式語言教學誌》的範例程式
     htt://pydoing.blogspot.com/
     檔名:block03.html
     功能:示範 CSS 2.1 樣式表的使用 
     作者:張凱慶
     時間:西元 2011 年 7 月 -->


瀏覽器開啟如下



使用數字或百分比如下例
.example1 {
    height: 200px;
}

.example2 {
    height: 25%;
}

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:block04.css
    功能:示範 CSS 2.1 樣式表的使用 
    作者:張凱慶
    時間:西元 2011 年 7 月 */


我們以下面的 HTML 文件載入
<html>
<head>
<title>網頁標題</title>
<link rel="stylesheet" type="text/css" 
      href="block04.css">
</head>
<body>
<img class="example1" src="example.jpg">
<img class="example2" src="example.jpg">
</body>
</html>

<!-- 《程式語言教學誌》的範例程式
     htt://pydoing.blogspot.com/
     檔名:block04.html
     功能:示範 CSS 2.1 樣式表的使用 
     作者:張凱慶
     時間:西元 2011 年 7 月 -->


瀏覽器開啟如下



中英文術語對照
性質property
區塊元素block element
關鍵字keyword
瀏覽器broswer


您可以繼續參考

JavaScript 範例

區塊相關


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


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

沒有留言: