使用CSS对齐div以填充父容器的宽度 [英] Justify divs with CSS to fill width of parent container
问题描述
我有一个页面的容器宽度为100%,所以它的整个屏幕宽度,我有几个DIV在网格结构,他们都有浮动:左边,没有设置宽度,只有10px的边距。
I have a page with a container width 100% so its the entire width of the screen, i have several DIVs in a grid structure, they all have float: left on them and no set width, just a margin of 10px.
有一个方法,使用CSS或jQuery,让div填充整个宽度,并证明自己适合的差距,所以边距随屏幕大小而变化。
Is there a method, using CSS or jQuery, to have the divs fill the entire width and justify themselves to fit the gaps, so the margin changes depending the screen size.
推荐答案
在此线程中查看三十的答案,一个没有JavaScript的纯CSS / HTML解决方案适用于所有浏览器 IE 6 。
Check out thirtydot's answer in this thread for a pure CSS/HTML solution without JavaScript that works in all browsers including IE 6.
http:// jsfiddle.net/thirtydot/EDp8R/
HTML:
<div id="container">
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<span class="stretch"></span>
</div>
CSS: p>
CSS:
#container {
border: 2px dashed #444;
height: 125px;
text-align: justify;
-ms-text-justify: distribute-all-lines;
text-justify: distribute-all-lines;
/* just for demo */
min-width: 612px;
}
.box1, .box2, .box3, .box4 {
width: 150px;
height: 125px;
vertical-align: top;
display: inline-block;
*display: inline;
zoom: 1
}
.stretch {
width: 100%;
display: inline-block;
font-size: 0;
line-height: 0
}
.box1, .box3 {
background: #ccc
}
.box2, .box4 {
background: #0ff
}
这篇关于使用CSS对齐div以填充父容器的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!