html - 如果没有高度像素值,我的背景图片无法加载

标签 html css bootstrap-4

我正在尝试加载图像作为背景图像作为响应式背景图像。但图像未加载。这是我的 CSS 代码。

.cover{
    height: auto;
    width: 100%;
    background-image: url(../img/cover.jpg);
    background-repeat:no-repeat;
    background-size:contain;
    background-position:center;
}

最佳答案

如果 div 没有内容,那么它的高度将为 0px,因此 背景图片 不会显示。尝试将高度设置为 350px100vh 。您可以通过提供 border 来检查 div 高度。引用此 Why doesn't the background image show up without specific width and height?更多细节,希望对你有帮助

关于html - 如果没有高度像素值,我的背景图片无法加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55877074/

相关文章:

html - 浏览器兼容性问题 : layout not working in Firefox

html - 垂直对齐 div 内的元素

bootstrap-4 - 一行上的多个单选按钮 - Bootstrap 4

javascript - Firefox 3.6.24 在某些图像上添加灰色边框

iphone - 如何在 iPhone sdk 中将 HTML 页面附加到我的邮件编辑器?

html - 如何将图像 float 在div之上

html - 输入类型密码 - 自动完成 "on"和 html 形式的 "current-password"有什么区别?

css - 图像在 Bootstrap 4 中没有响应

javascript - JQuery.animate() : HTML5 annimation with JQuery

javascript - 未定义的 DOM 元素 javascript,而 console.log 给出了它