如何让背景图片响应屏幕大小?
How to make the background picture responsive to the screensize?
我有一个主体背景图片,它固定在背景中,容器在它前面滚动。问题是图片会根据屏幕大小不断放大。当我想要修复它时。
我什么都有。这是代码,有什么想法吗? :
body {
background:url('http://www.markrehnstrom.com/img/bg-img.jpg');
background-image: url('http://www.markrehnstrom.com/img/bg-img.jpg');
background-attachment:scroll;
background-position: center;
background-repeat: no-repeat;
background-size: cover 100%;
background-origin: content-box;
overflow-x:hidden;
float:left;
}
.background-img:after{
background-position:left;
width:90%;
height:90%;
}
将 background-size
更改为固定值,例如 80px 60px
,或任何您需要的值。
如果您这样做,无论您如何更改 window 大小,图像的大小都将保持不变。
例如:background-size: 80px 60px;
另外,看看这个 link:http://www.w3schools.com/cssref/css3_pr_background-size.asp
我有一个主体背景图片,它固定在背景中,容器在它前面滚动。问题是图片会根据屏幕大小不断放大。当我想要修复它时。
我什么都有。这是代码,有什么想法吗? :
body {
background:url('http://www.markrehnstrom.com/img/bg-img.jpg');
background-image: url('http://www.markrehnstrom.com/img/bg-img.jpg');
background-attachment:scroll;
background-position: center;
background-repeat: no-repeat;
background-size: cover 100%;
background-origin: content-box;
overflow-x:hidden;
float:left;
}
.background-img:after{
background-position:left;
width:90%;
height:90%;
}
将 background-size
更改为固定值,例如 80px 60px
,或任何您需要的值。
如果您这样做,无论您如何更改 window 大小,图像的大小都将保持不变。
例如:background-size: 80px 60px;
另外,看看这个 link:http://www.w3schools.com/cssref/css3_pr_background-size.asp