这取决于你想做什么。
你可以使用 display: inline-block;
font-size
设置为 0。非常感谢! - Misha Moroshkodisplay: block
元素(实际上)在结尾会有一个换行符。一个让你保留块级元素样式,同时将其放入页面流中的选项是设置 display: inline-block
(当然,需要一些额外的工作来使IE表现正常)。position: relative
,并使用 left
规则来对齐它们。#together {
position: absolute;
display: inline-block;
margin;left:10px;
background-color:lightblue;
width:500px;
border:4px double blue;
}
<div id="together" style="left:10px">first div</div>
<div id="together" style="left:520px">second div</div>
<div id="together" style="left:1030px">third div</div>
<div id="together" style="left:1540px">fourth div</div>
<div id="together" style="left:2050px">fifth div</div>
<div id="together" style="left:2560px">sixth div</div>
<div id="together" style="left:3070px">seventh div</div>
<span></span><span></span><span></span><span></span>