我正在尝试加载图像作为背景图像作为响应式背景图像。但图像未加载。这是我的 CSS 代码。
.cover{
height: auto;
width: 100%;
background-image: url(../img/cover.jpg);
background-repeat:no-repeat;
background-size:contain;
background-position:center;
}
最佳答案
如果 div
没有内容,那么它的高度将为 0px
,因此 背景图片
不会显示。尝试将高度设置为 350px
或 100vh
。您可以通过提供 border
来检查 div 高度。引用此 Why doesn't the background image show up without specific width and height?更多细节,希望对你有帮助
关于html - 如果没有高度像素值,我的背景图片无法加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55877074/