css - div不向右浮动

标签 css html

为什么蓝色 div 不与绿色 div 相邻?

这是html。只有带边框的容器。

<div id="wrapper960"  style="min-height:350px; border:1px red solid">
<div class="content-sidebar-l" style="min-height:250px; border:1px yellow solid">&nbsp;</div>
<div class="content" style="min-height:250px; border:1px green solid"></div>
<div class="content-sidebar-r"style="min-height:250px; border:1px blue solid"></div>

</div>

这是中间有居中 div 的 CSS。

#wrapper960 {margin:0 auto; padding:0; width:960px;}

.content-sidebar-l {
  float: left; 
  width:170px; 
  margin:0; 
  padding:0;}
.content {
  margin:0 auto; 
  padding:1em 0 0 0; 
  width:610px; 
  background-color:#fff;}
.content-sidebar-r {
  float: right;
  width:160px; 
  margin:0; 
  padding:0;}

blue div floating right issue
(来源:imagesup.net)

它在 JSFiddle

最佳答案

将您的 HTML 重新排序为:

<div id="wrapper960"  style="min-height:350px; border:1px red solid">
<div class="content-sidebar-r"style="min-height:250px; border:1px black solid"></div>
<div class="content-sidebar-l" style="min-height:250px; border:1px yellow solid">&nbsp;</div>
<div class="content" style="min-height:250px; border:1px green solid"></div>
</div>​

jsFiddle example

您需要先将侧边栏向右浮动,否则如果将其放在最后,它就无法 float 到同样 float 的元素之上。

关于css - div不向右浮动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13938018/

相关文章:

php - 循环动态值中的表

javascript - 禁用动画期间单击按钮 Javascript/jQuery

CSS - 如果我制作两条对 Angular 线以形成 x 有没有办法将文本放置在交点处?

javascript - If/else 语句比较数字

html - flex-start 和 baseline 有什么区别?

javascript - 我想在同一张卡片中显示数据作为两列任何建议

html - 带有图像的 Outlook HTML 电子邮件

html - 响应式侧边栏

javascript - 如何将小数点后面的数字限制为2位?

javascript - 更改链接目标