css - fixed 背景固定视觉差效果

1、background-attachment 属性 - 设置背景图像是否固定或者随着页面的其余部分滚动

2、background-size— 把背景图片放大到适合元素容器的尺寸,图片比例不变;一般不考虑。
-----background-size:100% 100%; 按容器比例撑满,图片会变形;

/* 如果不需要兼容到手机可以直接写: */
.g-work-box {
	width: 100%;
	height: 900px;
	padding: 10px 0;
	background: url(../images/icon-work-bg.png) center no-repeat;
	/* background-size : 让元素铺满所视区域 */
	/* background-size: cover; */
	background-attachment: fixed;
	overflow: hidden;
}

如果项目需要响应式,手机屏不让他视觉差,可以写在大屏幕时:

/*当屏幕大于1025px时显示 */
@media screen and (min-width: 1025px) {
	.g-work-box {
		height: 900px;
		background-attachment: fixed;
	}
}

你可能感兴趣的:(CSS)