1.float
<style type="text/css">.totalFieldDiv{
margin-left:5px;
margin-right:5px;
background-color:#00CC66;
width:180px;
height:40px;
float:left
}
</style>
</head>
<body>
<div style="border:#000000 thin solid; height:40px; width:900px; overflow:auto">
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
</div>
<script src="jquery-2.0.3.min.js"></script>
<script>
</script>
</body>
当设置浮动时,就不能够设置左右滚动条。
overflow:所有主流浏览器都支持 overflow 属性。
这个属性定义溢出元素内容区的内容会如何处理。如果值为 scroll,不论是否需要,用户代理都会提供一种滚动机制。因此,有可能即使元素框中可以放下所有内容也会出现滚动条。
不能同float一起使用
overflow , overflow-yvisible:
不剪切内容也不添加滚动条。假如显式声明此默认值,对象将被剪切为包含对象的window或frame的大小。并且clip属性设置将失效
auto:
此为body对象和textarea的默认值。在需要时剪切内容并添加滚动条
hidden:
不显示超过对象尺寸的内容
scroll:
横向显示滚动条
2. display: inline-block;
<style type="text/css">
#pull-left-attendTotalField{
margin-left:10px;
display: inline-block;
overflow-y: auto;
white-space: nowrap;
}
.totalFieldDiv{
padding-left:5px;
padding-right:5px;
display: inline-block;
background-color:#00CC66;
width:180px;
height:40px;
}
</style>
<body>
<div id="pull-left-attendTotalField" style="width: 781px;">
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
<div class="totalFieldDiv">
</div>
</div>
</body>
display:
white-space: