1

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

我在右边有 1 个 div,它使用浮点数留在那里。当左侧的主容器小于右侧的容器时,右侧的容器似乎与包装纸重叠。

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;
}
4

1 回答 1

3

添加overflow: hidden;到您的包装器 div

小提琴

内容很少:FIDDLE

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

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

于 2013-08-14T22:33:00.230 回答