gpt4 book ai didi

html - 相对 DIV 宽度和高度

转载 作者:行者123 更新时间:2023-11-28 17:27:22 26 4
gpt4 key购买 nike

我想要一个 DIV,最大 90% 高度或 90% 宽度。我只想将图片作为背景放入 DIV 中,并且完整的 svg-image 应该是可见的。在移动设备和桌面设备上。

CSS:

.camera {
position:absolute;
background-image: url(../img/svg-bild.svg);
background-repeat: no-repeat;
background-position: center;
max-height: 90%;
max-width: 90%;
}

感谢您的帮助。

ps: 我用谷歌但找不到有用的东西。我知道它会在某个地方,但我只需要更少的时间来搜索 2 小时。

最佳答案

如果您希望背景图像不被裁剪并始终适合容器,您可以使用 background-size: contain; ( more info on MDN )

您还需要将 max-width/max-height 更改为 height/width 否则您的元素将具有 0 高度/宽度,因为它不包含任何内容:

.camera {
position:absolute;
background-image: url(../img/svg-bild.svg);
background-repeat: no-repeat;
background-position: center;
background-size:contain; /** add this **/
height: 90%; /** change this **/
width: 90%; /** change this **/
}

关于html - 相对 DIV 宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26887001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com