天天看点

css 使用background的时候自适应图片高度

定义容器

将容器定位到底部,设置高度为100%

.container{
	width: 100%;
	height: 100%;
	position: absolute;
	bottom: 0;
	background: url('./img/test.jpg') no-repeat;
	background-size: 100% 100%;
}
           

这样就可以让图片在不用固定高度的情况下,占满整个屏幕