Propriedade CSS background-repeat
Exemplo
Repita uma imagem de fundo apenas verticalmente:
body
{
background-image: url("paper.gif");
background-repeat: repeat-y;
}
Mais exemplos de "Experimente você mesmo" abaixo.
Definição e uso
A background-repeat
propriedade define se/como uma imagem de fundo será repetida.
Por padrão, uma imagem de fundo é repetida verticalmente e horizontalmente.
Dica: A imagem de fundo é colocada de acordo com a propriedade background-position . Se nenhuma posição de fundo for especificada, a imagem será sempre colocada no canto superior esquerdo do elemento.
Valor padrão: | repita |
---|---|
Herdado: | não |
Animavel: | não. Leia sobre animáveis |
Versão: | CSS1 |
Sintaxe JavaScript: | objeto .style.backgroundRepeat="repeat-x" |
Suporte ao navegador
Os números na tabela especificam a primeira versão do navegador que oferece suporte total à propriedade.
Property | |||||
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Observação: o IE8 e versões anteriores não oferecem suporte a várias imagens de plano de fundo em um elemento.
Sintaxe CSS
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
Valores de propriedade
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 |
Mais exemplos
Exemplo
Repita uma imagem de fundo na vertical e na horizontal (este é o padrão):
body
{
background-image: url("paper.gif");
background-repeat: repeat;
}
Exemplo
Repita uma imagem de fundo apenas horizontalmente:
body
{
background-image: url("paper.gif");
background-repeat: repeat-x;
}
Exemplo
Não repita uma imagem de fundo. A imagem será exibida apenas uma vez:
body
{
background-image: url("paper.gif");
background-repeat: no-repeat;
}
Exemplo
Usando background-repeat: space e 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;
}
Exemplo
Use diferentes propriedades de plano de fundo para criar uma imagem "herói":
.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 */
}
Páginas relacionadas
Tutorial de CSS: Fundo de CSS
Referência CSS: propriedade background-position
Referência HTML DOM: propriedade backgroundRepeat