html - 隐藏的溢出不适用于固定子项

标签 html css

所以,我正在尝试创建一个固定的背景,实际上它的工作原理。问题出在我的页脚上,因为它从主页退后,并且当用户滚动时它会显示。问题是当我放置固定图像时,它在主窗口中带有溢出:隐藏,但是溢出:隐藏不起作用。

这是一个没有图像的我的概念的摆弄:http://jsfiddle.net/7q8v1vsu/

这里是固定图像:http://jsfiddle.net/L4oofkso/

最后是代码:

<div id="main">
    <div id="main-content"></div>
    <div id="main-background">
        <img src="http://clickalifecoachblog.com/wp-content/uploads/2015/01/Child-Girl-Bear-Toy-Autumn-Leaves-Nature-Photo-HD-Wallpaper.jpg">
    </div>
</div>

<div id="footer">
    <div id="footer-inner"></div>
</div>

这是 CSS:

#main{
    position: relative;
    background: #749B35;
    margin-bottom: 70px;
    height: 800px;
    overflow: hidden;
    z-index: 10;
}


#main-background{
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    min-width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    z-index: 0;
}
#main-background > img{
    position: absolute;
    left: 0;
    top: 0;
    width: 1200;
    z-index: 0;
}


#footer{
    position: relative;
}
#footer-inner{
    position: fixed;
    background: #E76144;
    bottom: 0;
    width: 100%;
    height: 70px;
    z-index: 0;
}

有人知道这个问题是否可以仅用 CSS 来解决,或者我必须求助于 Javascript?

谢谢

最佳答案

如果是固定背景,为什么不使用合适的固定背景呢? http://jsfiddle.net/L4oofkso/1/

#main{
    position: relative;
    background: #749B35;
    margin-bottom: 70px;
    height: 800px;
    overflow: hidden;
    z-index: 10;
    background: url("http://clickalifecoachblog.com/wp-content/uploads/2015/01/Child-Girl-Bear-Toy-Autumn-Leaves-Nature-Photo-HD-Wallpaper.jpg") center center no-repeat;
    background-size: cover;
    background-attachment: fixed;
}

关于html - 隐藏的溢出不适用于固定子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28300156/

相关文章:

javascript - 当我们移出并滚动时下拉滚动问题

html - 如何删除我的 div 上方和下方的间隙?

css - 使文本字段的位置与按钮的位置匹配+将控件保持在原处

html - 标签显示略低于表单复选框?

html - 在 IE 中显示但在 chrome 中不显示的 div 的背景图像

html - 如何将 HTML5 数据属性添加到 Rails 表单标签标签?

html - 使图标出现在框的右上角

css - 如何有效地 float 图像或背景图像

javascript - Google Chrome 是否遵循 Firefox 规范

css - Primefaces googlemap 不呈现