背景图大小设置值

1,默认图片大小,图片不会变形

.demo {
	width: 500px;
	height: 400px;
	background-image: url('./img/1.png');
	background-repeat: no-repeat;
}

2, 按照父级div 最长边进行等比例缩放图片,图片不会变形

.demo {
	width: 500px;
	height: 400px;
	background-image: url('./img/1.png');
	background-repeat: no-repeat;
	background-size: cover;
}

3, 按照父级div 最短边进行等比例缩放图片,图片不会变形

.demo {
	width: 500px;
	height: 400px;
	background-image: url('./img/1.png');
	background-repeat: no-repeat;
	background-size: contain;
}

4,按照父级div百分比控制,图片可能会变形

.demo {
	width: 500px;
	height: 400px;
	background-image: url('./img/1.png');
	background-repeat: no-repeat;
	background-size: 100%, 80%;
}

你可能感兴趣的:(css)