css - 我的 div 布局有什么问题?

标签 css html

我似乎无法让我的页脚 div 转到底部。它总是在我的容器 div 的底部,但我的容器 div 总是高度:0。我尝试将溢出设置为隐藏在容器 div 中,但高度仍然为 0,这使我所有其他 div 都消失了。怎么了?这是我的 css 和 html。

谢谢。

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

    <head></head>

    <body background="images/bg.png">
        <div id="contentcontainer">
            <div id="header">
                <img src="images/banner.png" />
            </div>
            <div id="nav">
            </div>
            <div id="form">
                <!--This is where the form goes-->
            </div>
            <div id="content">
                <!--This is where the content goes-->
            </div>

            <div id="submission"></div>
            <div id="footer">
                <p id="footertext">Copyright © 2013 me.com. All rights reserved.</p>
            </div>
        </div>
    </body>

</html>

CSS:

@charset"utf-8";

/* CSS Document */
 #submission {
    width:500px;
    height:175px;
    position:absolute;
    left:320px;
    top:225px;
}
#header {
    width: 820px;
    height: 200px;
    position: absolute;
    left: 0px;
    top: 0px;
}
#nav {
    width: 820px;
    height: 50px;
    position: absolute;
    left: 0px;
    top: 150px;
}
#form {
    background-color: #FFFFFF;
    width: 820px;
    height: 175px;
    position: absolute;
    left: 0px;
    top: 200px;
    border-bottom: 1px;
    border-bottom-color: #666666;
    border-bottom-style: dashed;
}
#content {
    border: hidden;
    background-color: #FFFFFF;
    width: 820px;
    position: absolute;
    left: 0%;
    top: 376px;
    min-height: 1200px;
    height: auto;
}
#footer {
    background-color: #666666;
    width: 100%;
    height: 50px;
    position: absolute;
    bottom: 0;
}
#footertext {
    color: #FFF;
    text-align: center;
    position: absolute;
}
#contentcontainer {
    height: 100%;
    width: 820px;
    position: relative;
    top: -10px;
    background-color: #FFF;
    left: 20%;
}

最佳答案

容器 div 的高度为零,因为所有子项都定位为绝对。如果您可以在没有绝对定位的情况下实现相同的效果,您会注意到容器 div 实际上占用了一些空间。

让一切都绝对定位不是一个好主意。

关于css - 我的 div 布局有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20837917/

相关文章:

javascript - 滚动时将 div 保持在顶部但保持边距

php - 如何修复 "Strict Standards: Only variables should be passed by reference"?

javascript - 使用 Javascript 检测 Windows 8 屏幕键盘

html - 如何在 <li> 列表样式中添加加号 (+)?

html 和 CSS 图像分层和不透明度

html - 透视属性 (css3) 不适用于 Mozilla Firefox 浏览器

css - 非 "div"元素上的 Bootstrap4 容器流体

html - Bootstrap : Add Button to list-group-items

javascript - 在鼠标悬停时取消 Jquery Slider 事件

javascript - 在 HTML 页面上将 URL 解析为可读的 json 格式?