CSS 垂直拉伸背景图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12694559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 20:21:10  来源:igfitidea点击:

Vertically stretch background image

css

提问by user1539137

I am trying to figure out how to stretch a background image vertically. I am using CSS3 with 3 images in the following way:

我想弄清楚如何垂直拉伸背景图像。我通过以下方式使用带有 3 个图像的 CSS3:

background-image: url("left.png"), url("right.png"), url("center.png")
background-repeat: no-repeat, no-repeat, repeat-x
background-position: top left, top right, top

Now I want to stretch these images vertically to that they extend all the way to the bottom. Is there a way to do this?

现在我想将这些图像垂直拉伸到它们一直延伸到底部。有没有办法做到这一点?

回答by mr_mariusz

I'm late to the party here, but this is what worked for me:

我在这里参加聚会迟到了,但这对我有用:

background-size: auto 100%;

This will fit the image vertically and let the width do whatever it needs to do (i think it repeats by default). You can also set:

这将垂直适合图像并让宽度做任何它需要做的事情(我认为它默认重复)。您还可以设置:

background-repeat: no-repeat;

for it to not repeat the image in the horizontal direction.

因为它不会在水平方向上重复图像。

回答by Erind Dollaku

Try:

尝试:

background-size: 100% 100%;

first 100%is for the width and the second for the height. In your case you need the second set to 100%

第一个100%是宽度,第二个是高度。在您的情况下,您需要第二组100%