Zkratka pozadí CSS
CSS pozadí – vlastnost zkratky
Pro zkrácení kódu je také možné specifikovat všechny vlastnosti pozadí v jedné jediné vlastnosti. Toto se nazývá zkrácená vlastnost.
Místo psaní:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Můžete použít vlastnost zkratky background
:
Příklad
Pomocí vlastnosti zkratky nastavte vlastnosti pozadí v jedné deklaraci:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Při použití zkrácené vlastnosti je pořadí hodnot vlastnosti:
background-color
background-image
background-repeat
background-attachment
background-position
Nezáleží na tom, zda jedna z hodnot vlastnosti chybí, pokud jsou ostatní v tomto pořadí. Všimněte si, že ve výše uvedených příkladech nepoužíváme vlastnost background-attachment, protože nemá hodnotu.
Všechny vlastnosti pozadí 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) |