gpt4 book ai didi

css - 背景图片显示不正确

转载 作者:行者123 更新时间:2023-11-27 23:23:54 25 4
gpt4 key购买 nike

.header {
background-image: url('https://i.imgur.com/kdsPrQt.jpg');
height: 83vh;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
width: 100%;
}
<div class="header">
jkjk
</div>

这是完整的图像 https://i.imgur.com/kdsPrQt.jpg使用图像 src 时它显示没有问题 https://jsfiddle.net/ohzcdav9/但是当使用背景图片时就会出现这个问题。它应该是 100% 宽度并且应该显示整个图像。

最佳答案

您已将高度设置为83vh。将 height 设置为 100vh 将允许图像占据整个浏览器 height,从而允许显示完整图像,尽管它可能会扭曲图片基于您的浏览器尺寸(由于 background-size: cover)。

请注意,如果您将其用作整页背景,您还需要在 body 上设置 margin: 0 以避免滚动条,因为可以可见于以下:

body {
margin: 0;
}

.header {
background-image: url('https://i.imgur.com/kdsPrQt.jpg');
height: 100vh;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
width: 100%;
}
<div class="header"></div>

关于css - 背景图片显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57881735/

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