[英]CSS: How to make responsive background image that excluded the aspect ratio of the image?
I want to make a background image in the body that won't maintain the aspect ratio of the ratio. 我想在主体中制作一个背景图像,而该图像不会保持该比例的长宽比。
html,
body {
height: 100%;
background-image: url(../images/xmasbg13.jpg);
background-size: 100% 100%;
background-repeat: no-repeat;
}
The code above works fine if the browser window is in full screen. 如果浏览器窗口为全屏,则上面的代码可以正常工作。 But when I resize the browser, it maintains the aspect ratio of the image and won't cover the whole page. 但是,当我调整浏览器的大小时,它会保持图像的长宽比,并且不会覆盖整个页面。
How about background-size:cover
background-size:cover
如何background-size:cover
http://jsfiddle.net/2ez1e3mn/ http://jsfiddle.net/2ez1e3mn/
You can resize the results pane and the image resizes (full height and width) with it. 您可以调整结果窗格的大小,并使用它调整图像的大小(全高和全宽)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.