简体   繁体   English

跨背景高度缩放CSS图像

[英]Scale CSS Image Across Background Height

I'm trying to get a CSS image to scale depending on the size of the browser and maintain it's height:width ratio, however, I am particularly bad with website programming and at this point I've made a huge mess of the code. 我试图根据浏览器的大小来缩放CSS图像,并保持它的高度与宽度之比,但是,我对网站编程特别不满意,在这一点上,我已经弄乱了很多代码。 My image fits nicely with the proportions on my computer, but no matter what I seem to do it doesn't scale when I check on a bigger screen all I get is the exact same image with a huge gap on the bottom. 我的图像与计算机上的比例非常吻合,但是无论我似乎做什么,当我在更大的屏幕上查看时,它都不会缩放,而我得到的是完全相同的图像,底部有巨大的空隙。 I would provide my code but like I said, it's gotten pretty messy. 我会提供我的代码,但是就像我说的那样,它变得非常混乱。 Any suggestions? 有什么建议么?

use 采用

background-size: cover;

it will scale the image with your window 它将随着您的窗口缩放图像

https://developer.mozilla.org/en-US/docs/Web/CSS/background-size https://developer.mozilla.org/zh-CN/docs/Web/CSS/background-size

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

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