如何在另一个 div 中水平放置两个 div [英] How to position two divs horizontally within another div
问题描述
我已经很长时间没有使用 CSS 了,目前没有参考资料.我的问题应该很简单,但谷歌搜索并没有提供足够的答案.因此,添加到集体知识...
I haven't played with CSS for too long a time and am without references at the moment. My question should be fairly easy but googling isn't bringing up a sufficient answer. So, adding to the collective knowledge...
|#header---------------------------------------------------------------|
| TITLE |
|#sub-title------------------------------------------------------------|
|bread > crumb | username logout |
|#sub-left | #sub-right|
|---------------------------------|------------------------------------|
这就是我想要的布局.反正标题.我希望副标题包含子左和子右.我使用什么 css 规则来确保一个 div 受另一个 div 的属性约束.在这种情况下,如何确保 sub-left 和 sub-right 保持在副标题内?
That's what I'm wanting my layout to be. The heading anyways. I wanted sub-title to contain sub-left AND sub-right. What css rules do I use to ensure a div is bound by the attributes of another div. In this case, how do I ensure that sub-left and sub-right stay within sub-title?
推荐答案
这是一个很常见的误解,认为底部需要 clear:both
div,而实际上并不需要.虽然 Foxy 的回答是正确的,但您不需要那个非语义的、无用的清除 div.您需要做的就是将 overflow:hidden
粘贴到容器上:
Its quite a common misconception that you need a clear:both
div at the bottom, when you really don't. While foxy's answer is correct, you don't need that non-semantic, useless clearing div. All you need to do is stick an overflow:hidden
onto the container:
#sub-title { overflow:hidden; }
这篇关于如何在另一个 div 中水平放置两个 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!