CSS3 background-attachment:属性

12 篇文章 1 订阅

background-attachment :定义背景图片随滚动轴的移动方式


取值: scroll | fixed | inherit
scroll: 随着页面的滚动轴背景图片将移动
fixed: 随着页面的滚动轴背景图片不会移动
inherit: 继承初始值: scroll
继承性: 否
适用于: 所有元素 

 

HTML代码:

<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>CSS3 background-attachment 属性</title>
</head>

<body>

	<article>

		<div><img src="http://img.daimg.com/uploads/allimg/120224/3-120224210UR44.jpg" /></div>
		<div class="bg_img1"></div>

		<div><img src="http://img.daimg.com/uploads/allimg/140905/3-140Z51GT7.jpg" /></div>
		<div class="bg_img2"></div>

		<div><img src="http://www.daimg.com/uploads/allimg/120224/3-120224124141C4.jpg" /></div>
		<div class="bg_img3"></div>

		<div><img src="http://img.daimg.com/uploads/allimg/120224/3-120224144215557.jpg" /></div>
		<div class="bg_img4"></div>

	</article>
</body>

</html>

 

 

CSS代码:

	* {
			margin: 0px;
			padding: 0px;
			box-sizing: border-box;
		}
		pre {
			padding: 10px;
			font-size: 18px;
			position: fixed;
		}
		article {
			width: 1000px;
			margin: auto;
		}
		article div {
			width: 100%;
			height: 600px;
			box-shadow: 0px 0px 8px 2px gray;
		}
		article div img {
			width: 100%;
		}
		.bg_img1 {
			background: url(http://img.daimg.com/uploads/allimg/120225/3-120225130605612.jpg) no-repeat;
			background-size: cover;
			background-attachment: fixed;
		}
		.bg_img2 {
			background: url(http://img.daimg.com/uploads/allimg/140718/3-140GR33143.jpg) no-repeat;
			background-size: cover;
			background-attachment: fixed;
		}
		.bg_img3 {
			background: url(http://img.daimg.com/uploads/allimg/120405/3-120405120PL31.jpg) no-repeat;
			background-size: cover;
			background-attachment: fixed;
		}
		.bg_img4 {
			background: url(http://img.daimg.com/uploads/allimg/120224/3-12022421310L04.jpg) no-repeat;
			background-size: cover;
			background-attachment: fixed;
		}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值