Properti pengulangan latar belakang CSS
Contoh
Ulangi gambar latar belakang hanya secara vertikal:
body
{
background-image: url("paper.gif");
background-repeat: repeat-y;
}
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Properti background-repeat
menetapkan jika/bagaimana gambar latar akan diulang.
Secara default, gambar latar diulang baik secara vertikal maupun horizontal.
Tip: Gambar latar belakang ditempatkan sesuai dengan properti background-position . Jika tidak ada posisi latar belakang yang ditentukan, gambar selalu ditempatkan di sudut kiri atas elemen.
Nilai bawaan: | ulang |
---|---|
Diwarisi: | tidak |
Animasi: | tidak. Baca tentang animasi |
Versi: kapan: | CSS1 |
Sintaks JavaScript: | objek .style.backgroundRepeat="repeat-x" |
Dukungan Peramban
Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung properti.
Property | |||||
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Catatan: IE8 dan sebelumnya tidak mendukung banyak gambar latar belakang pada satu elemen.
Sintaks CSS
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
Nilai properti
Value | Description | Play it |
---|---|---|
repeat | The background image is repeated both vertically and horizontally. The last image will be clipped if it does not fit. This is default | |
repeat-x | The background image is repeated only horizontally | |
repeat-y | The background image is repeated only vertically | |
no-repeat | The background-image is not repeated. The image will only be shown once | |
space | The background-image is repeated as much as possible without clipping. The first and last image is pinned to either side of the element, and whitespace is distributed evenly between the images | |
round | The background-image is repeated and squished or stretched to fill the space (no gaps) | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Lebih Banyak Contoh
Contoh
Ulangi gambar latar belakang baik secara vertikal maupun horizontal (ini default):
body
{
background-image: url("paper.gif");
background-repeat: repeat;
}
Contoh
Ulangi gambar latar belakang hanya secara horizontal:
body
{
background-image: url("paper.gif");
background-repeat: repeat-x;
}
Contoh
Jangan ulangi gambar latar belakang. Gambar hanya akan ditampilkan sekali:
body
{
background-image: url("paper.gif");
background-repeat: no-repeat;
}
Contoh
Menggunakan background-repeat: space dan background-repeat: round:
#example2 {
border: 2px solid black;
padding: 25px;
background: url("w3css.gif");
background-repeat: space;
}
#example3 {
border: 1px solid black;
padding: 25px;
background: url("w3css.gif");
background-repeat: round;
}
Contoh
Gunakan properti latar belakang yang berbeda untuk membuat gambar "pahlawan":
.hero-image {
background-image: url("photographer.jpg"); /* The
image used */
background-color: #cccccc; /* Used if the image is
unavailable */
height: 500px; /* You must set a specified height */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
}
Halaman Terkait
Tutorial CSS: Latar Belakang CSS
Referensi CSS: properti posisi latar belakang
Referensi DOM HTML: properti backgroundRepeat