Propiedad de repetición de fondo CSS
Ejemplo
Repita una imagen de fondo solo verticalmente:
body
{
background-image: url("paper.gif");
background-repeat: repeat-y;
}
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La background-repeat
propiedad establece si/cómo se repetirá una imagen de fondo.
Por defecto, una imagen de fondo se repite tanto vertical como horizontalmente.
Sugerencia: la imagen de fondo se coloca de acuerdo con la propiedad background-position . Si no se especifica una posición de fondo, la imagen siempre se coloca en la esquina superior izquierda del elemento.
Valor por defecto: | repetir |
---|---|
Heredado: | No |
Animable: | No. Leer sobre animable |
Versión: | CSS1 |
Sintaxis de JavaScript: | objeto .style.backgroundRepeat="repetir-x" |
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con la propiedad.
Property | |||||
---|---|---|---|---|---|
background-repeat | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Nota: IE8 y versiones anteriores no admiten varias imágenes de fondo en un elemento.
Sintaxis CSS
background-repeat: repeat|repeat-x|repeat-y|no-repeat|initial|inherit;
Valores de propiedad
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 |
Más ejemplos
Ejemplo
Repita una imagen de fondo tanto vertical como horizontalmente (esto es predeterminado):
body
{
background-image: url("paper.gif");
background-repeat: repeat;
}
Ejemplo
Repita una imagen de fondo solo horizontalmente:
body
{
background-image: url("paper.gif");
background-repeat: repeat-x;
}
Ejemplo
No repita una imagen de fondo. La imagen solo se mostrará una vez:
body
{
background-image: url("paper.gif");
background-repeat: no-repeat;
}
Ejemplo
Usando background-repeat: space y 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;
}
Ejemplo
Use diferentes propiedades de fondo para crear una imagen de "héroe":
.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 CSS: Fondo CSS
Referencia de CSS: propiedad de posición de fondo
Referencia HTML DOM: propiedad backgroundRepeat