【发布时间】:2021-02-06 15:48:44
【问题描述】:
我的网站上有这个视差图像(大自然图像) This is how the page is normally seen
但它的大小不合适。当我打开 chrome 开发工具时,它看起来像下图,这就是我想要的样子。 this is the image how it needs to be (the nature image)
所以我想要什么:我希望在上面的图片中看到的自然图像显示为第二张图片中的样子(使用 devtools)。我知道图像的尺寸不适合盒子。但我不知道如何解决,也无法在 Internet 上找到相关内容。
有人可以帮助我吗? 如果我的问题不够清楚,请回复我应该补充的内容!
我的 CSS 代码附加到图像视差:
.header{
background-image: url("nav-bg.png"); //The background image
border-bottom-right-radius: 20px;
border-bottom-left-radius: 20px;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
.parallax-2 {
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
HTML 代码:
<div class="header parallax-2">
<div class="logo fade-in-3"><img src="logo.png" alt="BeldrProductions" width="500"></div>
<!-- The nav-items go here. but i left them out to save space-->
</div>
希望尽快看到你的答案! 贝尔德尔
注意: 以下答案的建议:
- 背景尺寸:包含不重复; (不起作用)
- object-fit:包含和 object-fit:cover(不起作用)
- 宽度和高度 100%(不)
我在 JSfiddle 上的代码:https://jsfiddle.net/BeldrProductions/k5f70dy9/
【问题讨论】:
-
你试过把它作为背景图片吗?如果不是,则将其作为 bg 并使用属性 background-size: contains no-repeat;并查看结果。
-
不起作用。它下面的文本移动了一点,但仅此而已。图像还是一样的
-
尝试在你的图像类中添加 object-fit: contains 和 object-fit: cover
-
不,还是一样。
-
您尝试过修复图像大小吗?高度:100%; (根据div)和宽度:100%;