Home  >  Article  >  Web Front-end  >  The use and definition of css background-attachment attribute

The use and definition of css background-attachment attribute

黄舟
黄舟Original
2017-06-21 11:17:022193browse

background-attachment -- Define how the background image moves with the scroll axis

Value: scroll | fixed | inherit

scroll: As the page scrolls The axis background image will move

fixed: The axis background image will not move as the page scrolls

inherit: Inherit

Initial value: scroll

Inheritance: No

Applies to: all elements

background: background.attachment: attachment.

Example

body 
{	
background-image:url('list-orange.png');	
background-attachment:fixed;	
background-repeat:repeat-x;	
background-position:center center;
}

The background image of the screen is An orange line. As the scroll axis moves, the visual position of the orange line remains unchanged.

CSS background-attachment property example--You can try editing

CSS background-attachment property example

Parallax Scrolling refers to making multi-layer backgrounds move at different speeds to form a three-dimensional motion effect and bring an excellent visual experience. As a hot trend in web design this year, more and more websites have applied this technology.

If you don’t understand, you can first take a look at the effect on eBay: http://www.ebay.com/new/

In fact, it is to fix the background and not let it move with the scroll axis, but The container containing the background is scrolled, causing a visual difference that appears to be the same as switching scenes. (Don’t let this explanation be too confusing...)

The attribute that defines the background scrolling method in CSS is background-attachment

background-attachment -- defines the way the background image moves with the scroll axis

Values: scroll | fixed | inherit

scroll: Default value. Background image will move as the rest of the page scrolls.

fixed: The background image does not move when the rest of the page scrolls.

inherit: Specifies that the setting of the background-attachment attribute should be inherited from the parent element.

Initial value: scroll

Inheritance: No

Applies to: all elements

Browser support:

It has been tested on chrome, opera, safari, firefox, and ie7-8, so it means that it does not work under IE6~

To use this attribute under IE6, you need to place background-attachment:fixed in the body Or in html, that is to say, it is useless in other tags. The effect you can see in the w3c above is because it is placed in the body.

This is a demo I made myself, click to download

Code:



    
        
        滚动视觉差示例
        
    

The above is the detailed content of The use and definition of css background-attachment attribute. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn