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

版权声明:尊重原创! https://blog.csdn.net/weixin_42675488/article/details/82956154

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;
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42675488/article/details/82956154