博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSS-背景附件 | background-attachment
阅读量:7002 次
发布时间:2019-06-27

本文共 3243 字,大约阅读时间需要 10 分钟。

如果指定了  ,那么  决定背景是在视口中固定的还是随包含它的区块滚动的。

/* Keyword values */background-attachment: scroll;background-attachment: fixed;background-attachment: local;/* Global values */background-attachment: inherit;background-attachment: initial;background-attachment: unset;

初始值

scroll

适用元素

all elements. It also applies to ::first-letter and ::first-line.

是否是继承属性

no

适用媒体

visual

计算值

as specified

Animation type

discrete

正规顺序

the unique non-ambiguous order defined by the formal grammar

语法

background-attachment属性被指定为下面列表中的一个关键字值。

fixed——此关键字表示背景相对于视口固定。即使一个元素拥有滚动机制,背景也不会随着元素的内容滚动。

local——此关键字表示背景相对于元素的内容固定。如果一个元素拥有滚动机制,背景将会随着元素的内容滚动, 并且背景的绘制区域和定位区域是相对于可滚动的区域而不是包含他们的边框。

scroll——此关键字表示背景相对于元素本身固定, 而不是随着它的内容滚动(对元素边框是有效的)。

正式语法

#where
= scroll | fixed | local

示例

简单例子

HTML

There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again.

CSS

p {
background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"); background-attachment: fixed;}

结果

多背景图支持

此属性支持多张背景图片。你可以用逗号分隔来为每一张背景图片指定不同的<attachment>。每一张背景图片顺序对应相应的attachment 类型。

HTML

There were doors all round the hall, but they were all locked; and when Alice had been all the way down one side and up the other, trying every door, she walked sadly down the middle, wondering how she was ever to get out again. Suddenly she came upon a little three-legged table, all made of solid glass; there was nothing on it except a tiny golden key, and Alice's first thought was that it might belong to one of the doors of the hall; but, alas! either the locks were too large, or the key was too small, but at any rate it would not open any of them. However, on the second time round, she came upon a low curtain she had not noticed before, and behind it was a little door about fifteen inches high: she tried the little golden key in the lock, and to her great delight it fitted!

CSS

p {
background-image: url("https://mdn.mozillademos.org/files/12057/starsolid.gif"), url("https://mdn.mozillademos.org/files/12059/startransparent.gif"); background-attachment: fixed, scroll; background-repeat: no-repeat, repeat-y;}

结果

规范

Specification

Status

Comment

CSS Backgrounds and Borders Module Level 3The definition of 'background-attachment' in that specification.

Candidate Recommendation

The shorthand property has been extended to support multiple backgrounds and the local value.

CSS Level 2 (Revision 1)The definition of 'background-attachment' in that specification.

Recommendation

No significant change.

CSS Level 1The definition of 'background-attachment' in that specification.

Recommendation

No significant change.

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

1.0

12

1.0

4

3.5

1.0

Multiple backgrounds

1.0

12

3.6

9.0

10.5

1.3

local

1.0

12

25

9.0

10.5

5.0

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

1.0

(Yes)

10.0

3.2

Multiple backgrounds

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

10.0

3.2

local

?

(Yes)

(Yes)

25

(Yes)

?

?

转载地址:http://agrvl.baihongyu.com/

你可能感兴趣的文章
(转)Mongoose学习参考文档
查看>>
将多个文件压缩成zip文件进行下载
查看>>
iOS项目集成react native就这几步
查看>>
H5实例教学--3D全景(ThreeJs全景Demo)
查看>>
php 扩展安装(随笔)
查看>>
Tech UP——EGO北京分会成立啦
查看>>
如何找到Kafka集群的吞吐量极限?\n
查看>>
52 个有用的机器学习与预测接口盘点
查看>>
恶意软件盯上了加密货币,两家以色列公司受到攻击
查看>>
Kubernetes日志分析利器:Elassandra部署使用指南
查看>>
Qt智能家居应用开发:硬件设备实现智能网络配置时候,如何使用第三方smart config 库...
查看>>
微软在C# 8中引入预览版可空引用类型
查看>>
Docker4Dev #7 新瓶装老酒 – 使用 Windows Container运行ASP.NET MVC 2 + SQLExpress 应用
查看>>
【关于数组】JavaScript常用的API
查看>>
Airbnb如何简化1000多位工程师的Kubernetes工作流程?
查看>>
2019年软件测试现状调查
查看>>
深度解读:如何评估软件测试工作的价值?
查看>>
BitBucket Cloud新增Git大文件存储Beta支持
查看>>
Java面试36题精讲:Oracle首席工程师帮你搞定BAT面试
查看>>
有赞搜索系统的架构演进
查看>>