Propiedad de archivo adjunto de fondo CSS
Ejemplo
Una imagen de fondo que no se desplazará con la página (fijo):
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: fixed;
}
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La background-attachment
propiedad establece si una imagen de fondo se desplaza con el resto de la página o si es fija.
Valor por defecto: | Desplazarse |
---|---|
Heredado: | No |
Animable: | No. Leer sobre animable |
Versión: | CSS1 |
Sintaxis de JavaScript: | objeto .style.backgroundAttachment="fijo" |
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-attachment | 1.0 | 4.0 | 1.0 | 1.0 | 3.5 |
Sintaxis CSS
background-attachment: scroll|fixed|local|initial|inherit;
Valores de propiedad
Value | Description |
---|---|
scroll | The background image will scroll with the page. This is default |
fixed | The background image will not scroll with the page |
local | The background image will scroll with the element's contents |
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
Una imagen de fondo que se desplazará con la página (scroll). Esto es predeterminado:
body {
background-image: url("img_tree.gif");
background-repeat: no-repeat;
background-attachment: scroll;
}
Ejemplo
Cómo crear un efecto de desplazamiento de paralaje simple (crear una ilusión de profundidad 3D):
.fixed-bg {
/* The background image */
background-image: url("img_tree.gif");
/* Set a specified height, or the minimum height for the background image */
min-height: 500px;
/* Set background image to fixed (don't scroll along with the page) */
background-attachment: fixed;
/* Center the background image */
background-position: center;
/* Set the background image to no repeat */
background-repeat: no-repeat;
/* Scale the background image to be as large as possible */
background-size: cover;
}
páginas relacionadas
Tutorial CSS: Fondo CSS
Referencia HTML DOM: propiedad backgroundAttachment