简体   繁体   English

背景图片无法缩放以适合网站

[英]background image doesn't scale to fit the site

Live demo: http://leoaivy.github.io/projects/poster_inside/html/1_P.01_login.html 现场演示: http : //leoaivy.github.io/projects/poster_inside/html/1_P.01_login.html

Questoin: ".login-bg-wrap a img" work well on desktop with max-width set to 100%. 问题:“。login-bg-wrap img”在桌面上的效果很好,最大宽度设置为100%。 But on narrower devices like iphone 6, the background images just scale to fit the width of view port, which make their height become smaller. 但是在像iPhone 6这样的较窄的设备上,背景图像只是按比例缩放以适合视口的宽度,这会使它们的高度变小。 I set heihgt to just 1% or 100% but they scale to their original size. 我将heihgt设置为仅1%或100%,但它们会缩放到其原始大小。 I don't know why? 不知道为什么 And is there a way to make the height of these images fit the height of the site? 有没有办法使这些图像的高度适合站点的高度?

You need to make sure that every element, down to the images, is set to have a width of 100%. 您需要确保每个元素(包括图像)的width都设置为100%。 And an extra min-width of whatever number you want to stop the shrinking at applied to the image itself. 而且,您想要停止缩小的任何数字的额外min-width都将应用于图像本身。

And only the width, not the height. 而且只有宽度,而不是高度。

You could remove the max-width , make the image's height and width 100%, and give it a object-fit: cover; 您可以删除max-width ,使图像的高度和宽度为100%,并使其object-fit: cover; Is that what you are trying to achieve? 那是您要达到的目标吗?

You can also use 100vw on the width, and 100vh on the height, so that way the image will always have the viewport's size. 您还可以使用100vw上的宽度, 100vh的高度,所以这样的形象将永远有视口的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM