用CSS换行
我连续有 7 个 div,内容都很少。我想要前 3 个一行,然后是下 3 个,依此类推。
<div class="parent">
<div class="child-a">abc</div>
<div class="child-b">def</div>
<div class="child-c">ghi</div>
<div class="child-d">jkl</div>
<div class="child-e">mno</div>
<div class="child-f">pqr</div>
<div class="child-g">stu</div>
</div>
那么我怎样才能做到这一点呢?
对于第一行,我有
.child-a, .child-b, .child-c {
padding: 0 2% 0 0;
width:100%
display: inline;
float: left;
}
child-c、child-d、child-e 的 css 是什么,以便它们显示在 child-a、child-b、child-c 下面而不是在同一行?
I have 7 divs in a row with all very little content. I want to have the first 3 one a line then the next 3, and so on.
<div class="parent">
<div class="child-a">abc</div>
<div class="child-b">def</div>
<div class="child-c">ghi</div>
<div class="child-d">jkl</div>
<div class="child-e">mno</div>
<div class="child-f">pqr</div>
<div class="child-g">stu</div>
</div>
So how can I make this work?
For the first line I have
.child-a, .child-b, .child-c {
padding: 0 2% 0 0;
width:100%
display: inline;
float: left;
}
What would the css be for child-c, child-d, child-e so that they would be displayed below child-a, child-b, child-c rather than on the same line?
My complete code: http://jsfiddle.net/winchendonsprings/UfswL/11/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更好的方法是这样的。
第三个之后的每个元素都将转到下一行。 演示
这是按照您的要求进行的
前 3 个一行,然后是下 3 个,然后尽管存在一些浏览器兼容性问题,但仍然有效。
A better way to go would be something like this.
Every element after the third will go to next line. Demo
This is do what you asked
the first 3 one a line then the next 3, and so on.
efficiently despites some browsers compatiblity issues.您忘记了类的点:
这将使“d”和“g”的左侧不能有浮动元素。
You forgot the dots for the classes:
This will make it so that 'd' and 'g' can't have a floated element to their left.
我得到的是你想要 3 个 div 在顶行,然后 3 个 div 在第二行,然后最后两个 div 在最后一行。如果这是正确的,那么您不需要 7 个 ID。而是使用一个类。
所有子 div 都必须使用此类。 div 会自动并排对齐。
可能会出现一些问题:
overflow:hidden;
或overflow:auto;
(“拉动”里面的子内容)width:32.5%;
因为它的工作方式有点不同。希望有帮助。What I am getting is you want 3 divs one top row, then 3 divs on second row, then the last two divs on last row. If that is correct, you dont need 7 ID's. Instead use one class.
All child divs must use this class. The divs will automatically align themselves side by side.
A couple of issues that may arise:
overflow:hidden;
oroverflow:auto;
("pulls" the child content inside)width:32.5%;
for example because it works a bit different. Hope it helps.