- left
- right
- top
- bottom
- center
left 為水平靠左, right 為水平靠右, top 為垂直置頂, bottom 為垂直置底center 則是水平或垂直都置中。
前後需設定兩組,若是數字或百分比前為水平後為垂直,若是關鍵字則順序無關,例如
background-position : 25% 50% ; /* 水平 25% ,垂直 50% */ background-position : 50px 25px ; /* 水平 50px ,垂直 25px */ background-position : center ; /* 水平垂直都 50% */ background-position : bottom right ; /* 水平 100% ,垂直 100% */ |
舉例如下
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 | div { margin : 2px ; width : 200px ; height : 200px ; border : thin solid black ; } .example 1 { background-image : url (gear.png); background-repeat : no-repeat ; background-position : 25% 50% ; } .example 2 { background-image : url (gear.png); background-repeat : no-repeat ; background-position : 50px 25px ; } .example 3 { background-image : url (gear.png); background-repeat : no-repeat ; background-position : center ; } .example 4 { background-image : url (gear.png); background-repeat : no-repeat ; background-position : bottom right ; } /* 《程式語言教學誌》的範例程式 檔名:background06.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 | < html > < head > < title >網頁標題</ title > < link rel = "stylesheet" type = "text/css" href = "background06.css" > </ head > < body > < table >< tr >< td > < div class = "examplerepeat" ></ div > </ td >< td > < div class = "examplerepeatx" ></ div > </ td ></ tr >< tr >< td > < div class = "examplerepeaty" ></ div > </ td >< td > < div class = "examplenorepeat" ></ div > </ td ></ tr ></ table > </ body > </ html > <!-- 《程式語言教學誌》的範例程式 檔名:background06.html 功能:示範 CSS 2.1 樣式表的使用 作者:張凱慶 時間:西元 2011 年 7 月 --> |
瀏覽器 (broswer) 開啟如下

中英文術語對照 | |
---|---|
性質 | property |
關鍵字 | keyword |
瀏覽器 | broswer |
您可以繼續參考
JavaScript 範例
背景相關
相關目錄
CSS 2.1 快速導覽
HTML, CSS 教材
首頁
參考資料
http://www.w3.org/TR/CSS21/colors.html
https://developer.mozilla.org/en/CSS/background-position
沒有留言:
張貼留言