简体   繁体   English

如何使3个div彼此并排,以使其位于底部和顶部div之间?

[英]How to have 3 divs aligned up next to each other so that they are in between a bottom and top div?

I want 3 divs to be aligned up next to each other so that they are in between a bottom and top div. 我希望3个div彼此并排对齐,以便它们位于底部和顶部div之间。 When floating all 3 divs to the left they are pushed to the bottom of the surrounding divs. 将所有3个div浮动到左侧时,它们将被推到周围div的底部。 If I float all the other divs it leaves a huge gap up top. 如果我将所有其他div浮动,则会在顶部留下巨大的空白。

There is another lot of divs to the left of these divs which have css clear:left . 这些div的左边还有另一个div,它们具有css clear:left When this is removed all the divs are the floated next too each other up the top of the page. 删除此选项后,所有div都将在页面顶部彼此浮动。

Is there an alternate route around aligning divs? 对齐div周围是否有替代路线? or am I just doing something wrong? 还是我做错了什么?

I don't know if you have anything against a responsive css framework like Bootstrap, but if you don't mind using it (or some of it's css): 我不知道您是否对Bootstrap之类的响应式CSS框架有任何疑问,但是如果您不介意使用它(或其中的某些CSS):

 .top { background-color: red; height: 200px; } .middle { background-color: blue; height: 200px; border-style: dotted; box-sizing: border-box; } .bottom { background-color: yellow; height: 200px; } .col-md-12, .col-sm-12, .col-xs-12 { width: 100%; float: left; } .col-md-4, .col-sm-4, .col-xs-4 { width: 33.33333%; float: left; } 
 <div class="top col-md-12 col-sm-12 col-xs-12"> </div> <div class="middle col-md-4 col-sm-4 col-xs-4"></div> <div class="middle col-md-4 col-sm-4 col-xs-4"></div> <div class="middle col-md-4 col-sm-4 col-xs-4"></div> <div class="bottom col-md-12 col-sm-12 col-xs-12"> </div> 

box-sizing: border-box; is just to prevent the border to overflow the last div to the next row. 只是为了防止边框将最后一个div溢出到下一行。

My guess is you need to give the bottom div clear: left so that it doesn't move above your three floating divs. 我的猜测是您需要给底部的div clear: left移动,以便它不会移到三个浮动div上方。

See The One True Layout for an example of this done successfully. 有关成功完成此操作的示例,请参见“一个真实布局 ”。

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

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