2010-09-16 65 views

回答

15

取决于你想要做什么。 您可以使用display: inline-block;

http://jsfiddle.net/sygL9/

+0

我不知道如何设置'font-size:0'到容器。非常感谢 ! – 2010-09-16 12:31:30

2

一个display: block元件是(有效地)将不得不在端换行符。一个选项,可以让你保持块元素的样式,而把它在页面流设置display: inline-block(当然,与some additional work获得即行为)

另一种选择是嵌套它们,它们都设置为position: relative和使用left规则来对齐它们。

0

如果你有改变的div来跨度元素的可能性,这将解决这个问题,而无需使用CSS

<span></span><span></span><span></span><span></span> 
-1

#together { 
 
    position: absolute; 
 
    display: inline-block; 
 
\t margin;left:10px; 
 
\t background-color:lightblue; 
 
\t width:500px; 
 
\t 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>

你在这里,连续七个divs

+1

对多个元素使用相同的ID? ID应该是唯一的。 – 2017-07-11 22:23:30