The CSS background properties define the background effects of an element.
CSS的background屬性可為元素定義背景效果。
設定背景顏色 Set the background color
This example demonstrates how to set the background color for an element.
執行個體:
代碼如下 |
複製代碼 |
body {background-color: yellow} h1 {background-color: #00ff00} h2 {background-color: transparent} p {background-color: rgb(250,0,255)}
|
標題一
標題二
段落
[ 可先修改部分代碼 再運行查看效果 ]
設定背景圖片 Set an image as the background
This example demonstrates how to set an image as the background
執行個體:
代碼如下 |
複製代碼 |
body { background-image:url('attachments/month_0612/52006129151936.jpg') }
|
[ 可先修改部分代碼 再運行查看效果 ]
重複背景圖片 How to repeat a background image
This example demonstrates how to repeat a background image.
執行個體:
代碼如下 |
複製代碼 |
body { background-image: url('attachments/month_0612/52006129151936.jpg'); background-repeat: repeat }
|
[ 可先修改部分代碼 再運行查看效果 ]
背景圖片水平重複 How to repeat a background image only horizontally
This example demonstrates how to repeat a background image only horizontally.
執行個體:
代碼如下 |
複製代碼 |
body { background-image: url('attachments/month_0612/52006129151936.jpg'); background-repeat: repeat-x }
|
[ 可先修改部分代碼 再運行查看效果 ]
背景圖片垂直重複 How to repeat a background image only vertically