简体   繁体   English

自动调整固定图像的大小以适合内容

[英]Automatically resize fixed image, to fit under content

Okay, so I have a simple one page website, that has content in div at top, and then an image at bottom. 好的,所以我有一个简单的单页网站,其内容在div顶部,然后是图像。 This image needs to be fixed to bottom, and it needs to automatically resize to fit under the div above. 该图像需要固定在底部,并且需要自动调整大小以适合上面的div。

Any ideas on what would be a good way to do this? 关于什么是实现此目的的好方法的任何想法? If I just set the image to: 如果我只是将图像设置为:

img {
    position: fixed;
    bottom: 0px;
}

it works at first, but on smaller screens, the image just covers the div above. 首先可以使用,但在较小的屏幕上,图像仅覆盖上方的div。 Setting max-height on image doesnt work either, as the div above the image sometimes covers 40% of the screens, and other times it covers 80% of screen. 在图像上设置最大高度也不起作用,因为图像上方的div有时会覆盖40%的屏幕,而有时它会覆盖80%的屏幕。

Any ideas at all on what else I can try? 关于我还能尝试什么的任何想法?

Try this: 尝试这个:

img {
  position: fixed;
  bottom: 0px;
  height: calc(100vh - 50px); # replace 50px with your "div above" height
}

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

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