CSS 将元素置于彼此下方
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14394348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Position elements under each other
提问by Kenny Bones
I have two elements I want to put next to each other, and three elements I want to put below the first two, like this:
我有两个要放在一起的元素,还有三个要放在前两个下面的元素,如下所示:
Element 1 Element 2
元素 1 元素 2
Element 3 Element 4 Element 5
元素 3 元素 4 元素 5
These are text elements actually, and no matter how long the text might be, I want them to still stay in that position. How do I do this without using  ?
这些实际上是文本元素,无论文本有多长,我都希望它们仍然保持在那个位置。如何在不使用 的情况下执行此操作?
回答by sandeep
If it's a text use <br>
for this. Write like this:
如果它是<br>
用于此的文本。像这样写:
Element 1 Element 2 <br>Element 3 Element 4 Element 5
& if it's HTML elements. Write like this:
& 如果是 HTML 元素。像这样写:
HTML
HTML
<div>element1</div>
<div>element2</div>
<div class="ele3">element3</div>
<div>element4</div>
<div>element4</div>
CSS
CSS
div{
float:left;
margin-right:5px;
}
.ele3{
clear:both;
}
Check this http://jsfiddle.net/K9Smv/
回答by Jeffrey Ray
Use <div>
tags to create two different containers.
使用<div>
标签创建两个不同的容器。
<div>
Element 1 Element 2
</div>
<div>
Element 3 Element 4 Element 5
</div>
回答by Niki Lichev
<div>
element1
element2
</div>
<div class="new_line">
element3
element4
element5
</div>
<div class="new_line">
element6
element7
element8
element9
</div>
div{
float:left;
margin-right:5px;
}
.new_line{
clear:both;
}