css 解决背景图片铺满全屏问题

4,817 阅读1分钟

记录一下 

background-attachment: fixed; 重点代码

demo 在下面

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		html,body{
			width: 100%;
			height: 100%;
		}
		.img{
			width: 100%;
			height: 100%;
			background: url(sy.png) no-repeat;
			background-size:100% 100%; 
			background-attachment: fixed;
		}
	</style>
	<body>
		<div class="img" id="img"><div>
	</body>
</html>