简体   繁体   English

CSS:Divs不左右排列

[英]CSS: Divs don't line up left and right

I have 2 divs. 我有2个div。 I want 1 div to be on the left side of my window and the other on the right side. 我希望1个div位于窗口的左侧,另一个位于右侧。 I did this correctly with my logo and a little text next to it. 我用我的徽标和旁边的一个小文字正确地做了这个。 However, under that I would like to have yet another 2 divs. 但是,根据这一点,我希望还有另外2个div。 I put those 2 divs in 1 div with style clear:both; 我将这2个div放在1个div中,风格clear:both; this div lines up nicely under the two others. 这个div很好地排在另外两个之下。 But once I do float: right; 但是,一旦我float: right; with the 2nd div, it goes outside the main div... Why? 与第二个div,它走出主要的div ...为什么?

The code: (This should be lined up to the left) 代码:(这应该排在左边)

#menu {
    background-color:#485D9C;
    margin-left:10px;
    text-align:center;
    width: 200px;
    position:absolute;
    float:left;
}

(This should be lined up to the right) (这应该排在右边)

#content {
    text-align:right;
    width:600px;
    position:absolute;
    float:right;
}

(This is the div where both "content" and "menu" are in) (这是“内容”和“菜单”都在的div)

#middle {
    clear:both;
    border: thick solid;
    position:relative;
}

Do you have an example ? 你有一个例子吗? With this little test: http://jsfiddle.net/BouFe/uHJQB/1/ it works ! 通过这个小测试: http//jsfiddle.net/BouFe/uHJQB/1/它有效!

Whenever I am using floats, I put a div, with "clear: both;" 每当我使用花车时,我都放了一个div,“clear:both;” applied to it, inside of the container that holds the elements that have the float applied to them. 应用于它,在容器内部,该容器包含应用浮动的元素。 An example of this can be found here , which I think is what you were looking for. 这里可以找到一个例子,我认为这就是你要找的东西。

try placing an outer div and set the position: relative; 尝试放置一个外部div并设置位置:relative; and the inner elements mark their position as absolute 内在元素标志着他们的绝对位置

Don't know exactly what's going on without seeing your code, but I'm wondering if you're simply just no clearing your floats? 如果没有看到你的代码,不知道到底发生了什么,但我想知道你是不是只是没有清理你的花车?

http://www.quirksmode.org/css/clearing.html http://www.quirksmode.org/css/clearing.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM