css - div left 和 div right 不在容器中并排 float

标签 css html

这里是 jsFiddle

#wrapper {
    margin:1px;
    height:auto;
    width:auto;
    float:left;
    clear:both
}
#wrapperR {
    margin:1px;
    height:auto;
    width:auto;
    float:right;
    clear:both;
}

在我的页面中它看起来像这样

  L
   R

但我希望它看起来像 LR 我希望 及其所有内容在 保持正确并肩并肩。

我添加了 clear:both;对于两个 div,我什至创建了一个 .clear{clear:both;} 并调整了宽度、填充和边距,但我仍然不能并排 float 它们。

我想知道我在看什么。

谢谢!

最佳答案

从以下位置删除 clear:both:

#wrapperR {
margin: 1px;
height: auto;
width: auto;
float: right;
clear: both; /* REMOVE THIS LINE*/
}

jsFiddle example

这里的 clear:both 规则意味着这个元素将被放置在它之前的任何 float 元素的下面。

关于css - div left 和 div right 不在容器中并排 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16322492/

相关文章:

javascript - 我想根据设备显示不同的图像

javascript - 如何加载 Font Awesome ie8 w/字体下载禁用

javascript - 在滚动另一个 div 内的窗口时让 div 可见

CSS 两个 Div 相互重叠

javascript - html2canvas 创建一个宽度和高度为零的 Canvas ?

css - 如何使用渐变填充元素之间的间隙

jquery - 如何在具有相同功能的 div 和按钮中分配空白区域?

html - 如何在 Bootstrap 3 中垂直对齐长标签

javascript - 无论子元素如何,强制 div 高度为 0

javascript - 使用 setInterval 启动/停止功能