CSS 背景圖片重複
CSS background-repeat
預設情況下,background-image
屬性會水平和垂直重複影像。
有些影像應該只水平或垂直重複,否則會看起來很奇怪,就像這樣:
如果上面的影像只水平重複(background-repeat: repeat-x;
),背景會更好看:
提示:要垂直重複影像,請設定 background-repeat: repeat-y;
CSS background-repeat: no-repeat
只顯示一次背景影像也由 background-repeat
屬性指定:
示例
只顯示一次背景影像
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
}
自己動手試一試 »
在上面的示例中,背景影像與文字放置在相同的位置。我們希望改變影像的位置,使其不過多幹擾文字。
CSS background-position
background-position
屬性用於指定背景影像的位置。
示例
將背景影像定位在右上角:
body {
background-image: url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
自己動手試一試 »
CSS 背景重複和位置屬性
屬性 | 描述 |
---|---|
background-position | 設定背景影像的起始位置 |
background-repeat | 設定背景影像的重複方式 |
影片:CSS 背景重複和位置

