- static
- relative
- absolute
- fixed
static 使元素形如矩形方塊, relative 使元素位於相對位置, absolute 使元素固定在承載區塊 (containing block) 中的絕對位置, fixed 的承載區塊為可視區域 (viewport) 。
舉例如下
img { width: 35%; height: 35%; float: right; } .exampleabsolute { position: absolute; } .examplerelative { position: relative; } /* 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:visual04.css 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 */
我們以下面的 HTML 文件載入
<html> <head> <title>網頁標題</title> <link rel="stylesheet" type="text/css" href="visual04.css"> </head> <body> <img class="exampleabsolute" src="example.jpg"> <img class="examplerelative" src="example.jpg"> <div> You ever have that feeling where you're not sure if you're awake or still dreaming? A prison for your mind. Free your mind. Believe the unbelievable. There is no spoon. I can only show you the door, you have to walk through it. Choice. The problem is choice. Then tomorrow we may all be dead, but how would that be different from any other day? I have dreamed a dream, but now that dream has gone from me. Choice is an illusion, created between those with power, and those without. Because I choose to. Everything that has a beginning has an end.</div> </body> </html> <!-- 《程式語言教學誌》的範例程式 http://pydoing.blogspot.com/ 檔名:visual04.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 -->
瀏覽器 (broswer) 開啟如下
中英文術語對照 | |
---|---|
性質 | property |
元素 | element |
關鍵字 | keyword |
承載區塊 | containing block |
可視區域 | viewport |
瀏覽器 | broswer |
您可以繼續參考
JavaScript 範例
定位相關
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/visuren.html
https://developer.mozilla.org/en/CSS/position
沒有留言:
張貼留言