Containing Div Not Behaving Correctly When Child Divs are Floating

痞子三分冷 提交于 2019-12-24 06:28:54

问题


This question is related to another question I asked

Basically, I have 2 horizontally aligned divs. Both sit inside a div called ".Parent", so the structure is like this:

 <div class="Parent">
    <div style="float:right">
        <span>source list</span>
        <select size="10">
            <option />
            <option />
            <option />
        </select>
    </div>

    <div style="float:left">
        <span>dest list</span>
        <select size="10">
            <option />
            <option />
            <option />
        </select>
    </div>

    <div style="clear:both; font-size:1px;"></div>

 </div>

The problem is that the Parent div exists inside a another div called #main. #main has a white background that frames all of my content.

Before I added the floats to the divs inside .Parent, everything was fine because the containing Div pushed the white background down to the right size. But now that the divs are floating, they don't push #main's white background down.

Can anyone suggest how to get the #main to recognise the size it's supposed to strech down to? Should I approach this differently?

Thanks

Dave


回答1:


Give your #main overflow:hidden; and optionall clear:both;




回答2:


Actually, they ARE behaving correctly and parent divs are never to expand to contain floated elements. As shown by other answers, you can Google for "clear floats" for more explanations and examples of how to do this.



来源:https://stackoverflow.com/questions/2417585/containing-div-not-behaving-correctly-when-child-divs-are-floating

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!