Singkatan Latar Belakang CSS
Latar belakang CSS - Properti singkatan
Untuk mempersingkat kode, dimungkinkan juga untuk menentukan semua properti latar belakang dalam satu properti tunggal. Ini disebut properti singkatan.
Alih-alih menulis:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Anda dapat menggunakan properti singkatan background
:
Contoh
Gunakan properti singkatan untuk mengatur properti latar belakang dalam satu deklarasi:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Saat menggunakan properti singkatan, urutan nilai properti adalah:
background-color
background-image
background-repeat
background-attachment
background-position
Tidak masalah jika salah satu nilai properti hilang, selama yang lain dalam urutan ini. Perhatikan bahwa kami tidak menggunakan properti lampiran latar belakang dalam contoh di atas, karena tidak memiliki nilai.
Semua Properti Latar Belakang CSS
Property | Description |
---|---|
background | Sets all the background properties in one declaration |
background-attachment | Sets whether a background image is fixed or scrolls with the rest of the page |
background-clip | Specifies the painting area of the background |
background-color | Sets the background color of an element |
background-image | Sets the background image for an element |
background-origin | Specifies where the background image(s) is/are positioned |
background-position | Sets the starting position of a background image |
background-repeat | Sets how a background image will be repeated |
background-size | Specifies the size of the background image(s) |