当div小于其他div时,嵌套的div重叠

时间:2013-08-14 22:26:57

标签: html css

我正在处理一个带有Wrapper div的页面,它是容器。

我右边有1个div,它使用float来保持在那里。当左侧的主容器小于右侧容器时,右侧容器似乎覆盖了包装物。

HTML

    <body>
    <div id="Wrapper">
        <div id="Title">Title</div>
        <div id="SubTitle">SubtTitle</div>
        <br />
        <div id="Menu">Home | Our Story | Share A Memory | Information | About Us</div>
        <br />
        <div id="CountDown">
            <div id="CountDownTitle">Title</div>
            <hr />
            Some<br />
Random<br />
stuff<br />
        </div>
        <div id="Info">
            This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test. 
        </div>    
    </div>
</body>

CSS

body {
    background-image: url('../PNGs/Background.png');
    font-family: "Palatino Linotype";
    font-size: 14px;
}
#CountDown {
    background-color: #FFFFFF;
    border: 1px black solid;
    font-family: "Palatino Linotype";
    font-size: 12px;
    float: right;
    height: auto;
    opacity: 0.6;
    padding-bottom: 10px;
    padding-left: 10px;
    padding-right: 10px;
    text-align: center;
    text-shadow: 0px, 0px, #000000;
    width: 20%;
}
#CountDownTitle {
    color: #000000;
    font-family: Pristina;
    font-size: 16px;
    font-weight: bold;
    margin-top: 10px;
    src: url('../Elements/PRISTINA.ttf');
    text-align: center;
}
#Info {
    background-color: #FFFFFF;
    border: 1px black solid;
    font-family: "Palatino Linotype";
    display: block;
    height: auto;
    opacity: 0.6;
    padding-bottom: 10px;
    padding-left: 10px;
    padding-right: 10px;
    padding-top: 10px;
    text-align: justify;
    text-shadow: 0px, 0px, #000000;
    width: 70%;
}
#Menu {
    background-color: #FFFFFF;
    border: 1px black solid;
    display: block;
    height: 50px;
    opacity: 0.6;
    width: 100%;
}
#SubTitle {
    color: #FFFFFF;
    font-family: Pristina;
    font-size: 18px;
    src: url('../Elements/PRISTINA.ttf');
    text-align: center;
}
#Title {
    color: #FFFFFF;
    font-family: Pristina;
    font-size: 48px;
    src: url('../Elements/PRISTINA.ttf');
    text-align: center;
}
#Wrapper {
    border: 1px black solid;
    clear: both;
    height: auto;
    margin-bottom: auto;
    margin-left: auto;
    margin-right: auto;
    margin-top: 75px;
    width: 800px;
    z-index: 1;
}

1 个答案:

答案 0 :(得分:3)

overflow: hidden;添加到您的Wrapper div

<强> FIDDLE

内容很少: FIDDLE

这样做的原因是因为当溢出未设置为可见(默认值)时,这会创建一个新的块格式化上下文。

当div创建一个新的块格式化上下文时,它会在高度上拉伸以包含其浮动元素(假设div本身没有指定的高度。)