mozilla
您的搜索结果

    background-attachment

    概述

    如果指定了 background-image ,那么 background-attachment 决定背景图像是在视角中固定的还是随滚动条滚动的。

    If a background-image is specified, the background-attachment CSS property determines whether that image's position is fixed within the viewport, or scrolls along with its containing block.

    语法

    background-attachment: scroll;
    background-attachment: fixed;
    background-attachment: local;
    
    background-attachment: inherit;

    取值

    fixed
    This keyword means that the background is fixed with regard to the viewport. Even if an element has a scrolling mechanism, a ‘fixed’ background doesn't move with the element.
    local
    This keyword means that the background is fixed with regard to the element's contents: if the element has a scrolling mechanism, the background scrolls with the element's contents, and the background painting area and background positioning area are relative to the scrollable area of the element rather than to the border framing them.
    scroll
    This keyword means that the background is fixed with regard to the element itself and does not scroll with its contents. (It is effectively attached to the element's border.)
    scroll 
    如果设为 scroll,背景图片会随着包含它的区块一起滚动。
    fixed 
    如果设为 fixed,背景图片不会随着包含它的元素一直滚动,而是一直固定固定在屏幕的一个位置。

    形式化语法

    <attachment>#
    

     

     

    例子

    查看示例

    body {
      background-image: url("images/cartooncat.png");
      background-attachment: fixed;
    }
     
     
     
     
     

    Multiple background image support

    This property supports multiple background images. You can specify a different <attachment> for each background, separated by commas:

    body {
      background-image: url("img1.png"), url("img2.png");
      background-attachment: scroll, fixed;
    }
     
     
     
     
     

    Each image is matched with the corresponding attachment type, from first specified to last.

     

    查看在线演示

    body {
    	background-image: url("images/cartooncat.png");
    	background-position: bottom left;
    	background-attachment: fixed;
    	background-repeat: no-repeat;
    }
    

    规范

    Specification Status Comment
    CSS Backgrounds and Borders Module Level 3
    background-attachment
    Candidate Recommendation The shorthand property has been extended to support multiple backgrounds and the local value.
    CSS Level 2 (Revision 1)
    background-attachment
    Recommendation No significant change.
    CSS Level 1
    background-attachment
    Recommendation No significant change

    浏览器兼容性

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support 1.0 1.0 (1.7 or earlier) 4.0 3.5 1.0
    Multiple backgrounds 1.0 3.6 (1.9.2) 9.0 10.5 1.3
    local 4.0 25 (25) 9.0 10.5 5.0
    Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
    Basic support 2.1 1.0 (1.9.2) ? 10.0 3.2
    Multiple backgrounds 2.1 1.0 (1.9.2) ? 10.0 3.2
    local ? 25.0 (25) ? ? ?

    参见

    文档标签和贡献者

    标签: 
    Contributors to this page:
    最后编辑者: FredWe,