如何使div包含一切

and*_*rew 0 html css

我在jsfiddle有一个程序,我想知道我应该让div绕过一切.绕过一切我的意思是绕过一切.(更有效的jQuery代码将不胜感激;).)这是代码:

div {
    border:2px red outset;
}
div#container {
    width:50%;
}
div.section {
    position:relative;
    width:48%;
    display:inline;
    float:left;
}
    h3 {
    display:inline;
    width:48%;
    float:left;
    margin:0.65;
    text-align:center;
} a {
    display:inline;
    width:23%;
    float:left;
    margin:0.65%;
    text-align:center;
}
Run Code Online (Sandbox Code Playgroud)

我的HTML:

<div id="container">
    <h3>Section 1</h3>

    <h3>Section 2</h3>
    <br />
    <br /> <a href="#sec1" class="hide">Hide</a><a href="#sec1" class="show">Show</a>
    <a href="#sec2" class="hide">Hide</a><a href="#sec2" class="show">Show</a>

    <div id="sec1" class="section">Some content</div>
    <br />
    <div id="sec2" class="section">Some more content</div>
</div>
Run Code Online (Sandbox Code Playgroud)

j08*_*691 5

添加overflow:auto到您的容器div:

div#container {
    width:50%;
    overflow:auto;
}
Run Code Online (Sandbox Code Playgroud)

jsFiddle例子

当您浮动子项时,父项本质上会从浮动子项从文档流中删除时收缩.添加溢出规则可恢复您期望的布局.你的jQuery看起来很好.