float + 两层DOM实现html
1 2 3
css
.container { width: 200px; overflow: hidden; } /* float:left */ .div1 { overflow: hidden; width: 700px; } .div1 > div { width: 200px; float:left; margin-left: 10px; background: green; border:1px solid red; }
display:inline-block + 两层DOM 实现
/* display: inline-block */ .div2 { overflow: hidden; width: 700px; } .div2 > div { width: 200px; display: inline-block; border: 1px solid green; }
white-sapce:nowrap 减少一层DOMhtml
/* white-sapce: nowrap 能减少一层DOM*/ .div3 { white-space: nowrap; overflow: hidden; } .div3 > div { width: 200px; display: inline-block; border: 1px solid blue; }