所以我尝试使用 img 标签在 html/css 中制作背景 img 但我的 img 标签不允许东西重叠它并且当我尝试使用 div 类元素时它不会拉伸(stretch)到边缘即使宽度为 100% 的页面。这是我的 css 和 html。
.backgroundImage {
background: url(/images/mainBackground.jpeg) top no-repeat;
width: 100%;
height: auto;
position: relative;
z-index: 0;
margin: 0 auto;
}
.img{
z-index:0;
}
.img-responsive{
height:auto;
width:100%
}
这是我尝试过的两种方式:
<img src="../images/mainBackground.jpeg" class="shadow-offset img-responsive"/>
<div class="backgroundImage">
除了我的页脚之外,div 结束
我有容器,但它们都不在任何容器内,因为它们在我使用容器之前就从页面顶部开始。
最佳答案
将所有 html 包装在 <html>
中标记,然后使用以下 css:
html {
background-image: url("image/url.png");
}
关于html - img 标签不允许重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48445390/