CSS中水平div之间的自动间距 [英] auto space between horizontal divs in CSS
问题描述
我已经搜索了很多东西,但是我很不幸运地找到了解决我所追求的方案的方法!
这里是问题:我创建了一个主div(宽度100%),并且其中有几个内部div.您可以在这里看到它:中,我添加了4个内部div,但是,我追求的解决方案应该可以没关系,我有多少个div(例如2、3、4、5,...等)div.
预先感谢您的帮助.
假设您有100%,并且有4件.4件表示您有3个左边距空白,因此,当您使div 22 * 4 = 88然后100-88 = 12然后12/3 = 4时您的左边距必须为:4
div.box_frame {向左飘浮;背景颜色:#eee;/*标准背景色*/边框:1px实线#898989;border-radius:11px;填充:2px;剩余边距:4%;文本对齐:居中;/*将边框更改为框内*/box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;}div.box_frame:第一个孩子{左边距:0;}div.box_frame#_15 {/*宽度15%*/宽度:22%;}
因此,如果使用较少的变量,则可以使用此解决方案而无需依赖div块的数量
I've searched a lot but I was not lucky to find a solution to what I am after!
Here is the issue: I've created a master div (width 100%) and within it there are several inner divs. You can see it here: http://jsfiddle.net/EAkLb/1/
HTML:
<div class="section_zone">
<div class="box_frame" id="_15">inner box 1</div>
<div class="box_frame" id="_15">inner box 2</div>
<div class="box_frame" id="_15">inner box 3</div>
<div class="box_frame" id="_15">inner box 4</div>
</div>
What I am trying to accomplish is to auto the space-width between the inner divs.
the first-child is aligned to left, and the last-child is aligned to the right, but as you can see, the space between the other divs is not the same.
I hope the following demonstration image be helpful to explain what I am after exactly:
Please Note: in the fiddle, I've added 4 inner divs but, the solution I'm after should work no mater how many divs I have (e.g. 2, 3, 4, 5, ...etc) divs.
Thanks in advance for your help.
Assume that you have 100% and you have 4 pieces. 4 pieces means you have 3 margin-left block so, when you make your div 22*4=88 then 100-88=12 then 12/3=4 then your margin-left must be:4
div.box_frame{
float: left;
background-color: #eee; /* standard background color */
border: 1px solid #898989;
border-radius: 11px;
padding: 2px;
margin-left:4%;
text-align: center;
/* change border to be inside the box */
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
div.box_frame:first-child{
margin-left: 0;
}
div.box_frame#_15{ /* width 15% */
width: 22%;
}
So if you use less variables then you can use this solution without depending on number of div blocks
这篇关于CSS中水平div之间的自动间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!