Scorciatoia di sfondo CSS
Sfondo CSS - Proprietà abbreviata
Per abbreviare il codice è anche possibile specificare tutte le proprietà di sfondo in un'unica proprietà. Questa è chiamata proprietà abbreviata.
Invece di scrivere:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Puoi usare la proprietà abbreviata background
:
Esempio
Utilizzare la proprietà shorthand per impostare le proprietà di sfondo in una dichiarazione:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Quando si utilizza la proprietà shorthand, l'ordine dei valori della proprietà è:
background-color
background-image
background-repeat
background-attachment
background-position
Non importa se uno dei valori della proprietà è mancante, purché gli altri siano in questo ordine. Si noti che non utilizziamo la proprietà background-attachment negli esempi precedenti, poiché non ha un valore.
Tutte le proprietà di sfondo 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) |