html - div 高度与最小高度相同的背景图像

标签 html css image responsive

我正在尝试将一个响应式表单放入一个 div 中,该表单的背景图像占满了屏幕的整个宽度。搜索了一段时间后,似乎使背景图像 div 成为图像的完整大小的最佳选择是使用图像大小的填充底部。 现在的问题是,当我在较小的屏幕上观看它时,背景图像 div 太小以适应表单的内容。我尝试使用 min-width:100% 但这没有帮助。

html:

<div class="background-image-div">
    <div class="centerer-div">
        <form id="form">
           "some form stuff"
        </form>
    </div>
</div>

CSS:

.background-image-div{
    background-image: url(background.png)
    background-repeat: no-repeat;
    background-position-x: center;
    background-position-y: top;
    width: 100%;
    background-size: contain;
    position: relative;
    padding-bottom: 25%;
}
.centerer-div{
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto;
    height: auto;
    display: table;
    width: 100%;
}
#form{
    text-align: center;
}

最佳答案

可能是因为您没有关闭表单标签?

<div class="background-image-div">
    <div class="centerer-div">
        <form id="form">
           "some form stuff"
        </form>
    </div>
</div>

关于html - div 高度与最小高度相同的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36353731/

相关文章:

javascript - 在网站内单击时将 javascript 变量(trailimage)交换为另一个需要什么代码

javascript - 按时间选择带有 javascript 的样式表不起作用

javascript - asp.net中panzoom库和window.print()的问题

javascript - 如何在 td 上应用 css,其中每列的 css 类在 angular js 中是分开的

html - 中间重叠个人资料图片

php - 尝试显示以 base64 编码的图像

html - 禁用基于按钮的分页

css - 以符合 HTML5 的方式将 <hr> 左对齐

CSS div 拉伸(stretch)到整个浏览器宽度

html - 边框添加像素到div