Abreviação de fundo CSS
Fundo CSS - propriedade abreviada
Para encurtar o código, também é possível especificar todas as propriedades do plano de fundo em uma única propriedade. Isso é chamado de propriedade abreviada.
Em vez de escrever:
body {
background-color: #ffffff;
background-image:
url("img_tree.png");
background-repeat: no-repeat;
background-position: right top;
}
Você pode usar a propriedade abreviada background
:
Exemplo
Use a propriedade abreviada para definir as propriedades do plano de fundo em uma declaração:
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
Ao usar a propriedade abreviada, a ordem dos valores da propriedade é:
background-color
background-image
background-repeat
background-attachment
background-position
Não importa se um dos valores da propriedade está faltando, desde que os outros estejam nesta ordem. Observe que não usamos a propriedade background-attachment nos exemplos acima, pois ela não possui um valor.
Todas as propriedades de plano de fundo 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) |