在容器内浮动div,文本漏出容器的底部,我希望它在容器内.

4 html css css-float

我在容器内有2个div,每个内部div都向左和向右浮动,我想在主内容div中为数据创建2列.目前,文本泄漏了内容左侧和内容右侧的底部,即使它们包含在内容中.

这是一个jsfiddle

<div id="content">
    <div id="content-left">I want to put content in here<br/><br/><br/>This is outside? why?    </div>
    <div id="content-right">and more in here</div>
    Maybe other content here, inside the content
</div>
Run Code Online (Sandbox Code Playgroud)

和CSS

#content-left{
width: 50%;
border: 1px dotted #aaa;
float: left;
}

#content-right{
width: 49%;
float: right;
border: 1px dotted #aaa;
}

#content{
background-color: #eee;
width: 95%; /* Width of Main Content Div, % for Fluid*/
height: auto;
max-width: 1350px; /*Max width, To wide on big monitor*/
margin: 0 auto;
padding: 10px;
padding-left: 20px;
padding-right: 20px;
}
Run Code Online (Sandbox Code Playgroud)

此外,关于浮动物品的任何提示都会很棒,如果我发现它们有用,可能会获得代表,我认为我掌握了它但显然没有!:P

Jas*_*aro 6

你只需要br在最后一个内添加一个清算div

 Maybe other content here, but this should be below the 2 above divs in the rendered view.
    <br style="clear:both;" />
</div>
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/jasongennaro/sahbz/9/

发生这种情况是因为floated元素已从文档流中取出.