简体   繁体   English

如何调整背景图片的大小?

[英]How to resize background image?

I followed a tutorial about resizing background images on this link 我遵循了有关在此链接上调整背景图像大小的教程

How To: Resizeable Background Image 如何:可调整大小的背景图片

I was trying to edit it to work on div with width of 900px so it will resize only vertically and I have no idea how to make it work. 我试图对其进行编辑以在宽度为900px的div上工作,因此它只能垂直调整大小,而且我不知道如何使其工作。

Any one can tell me how to do it as I want. 任何人都可以告诉我如何做。

Thanks 谢谢

Are you using the first, second or third approach? 您使用的是第一,第二还是第三种方法?

Considering the third approach, it might simply work if you change width to height : 考虑到第三种方法,如果将width更改为height ,则可能简单地起作用:

#img.source-image {
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

In case this doesn't work, have a look at this question and this other question and experiment with your body height and DOCTYPE . 如果这不起作用,请查看此问题其他问题,并尝试使用您的身高和DOCTYPE You might also want to ask the same question on doctype.com . 您可能还想在doctype.com上问同样的问题。

Seems like this: 看起来像这样:

#yourDiv{
    background-size:cover}

But the compatibility is limited. 但是兼容性是有限的。 Example here . 这里的例子

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

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