使div内容水平滚动而不是垂直滚动

时间:2012-03-23 19:04:42

标签: css overflow horizontal-scrolling

我有一个带有一些内容的div,一堆拇指,我希望它们始终是水平的,任何溢出都会水平滚动。我希望div占据100%的宽度,保持拇指成为一组中心,这意味着当页面更宽时,它们保持居中并且不会粘在左边。我有一个jsfiddle,似乎无法弄清楚为什么它不工作,它总是将溢出推到第二行,而不是允许溢出功能接管。

http://jsfiddle.net/z5nEQ/1/这就是小提琴和代码:

的CSS:

#wrapper{
  width:100%;
  height:90px;
  border:1px solid red;
}

.box{
  width:50px;
  height:100px;
  border:1px solid black;
  float:left;
}

#container{
  width:100%;
  height:200px;
  float:left;
  overflow-x:scroll;
}

HTML:

<div align="center" id="wrapper">
  <div id="container">
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
    <div class="box"></div>
  </div>   
</div>​

对此有何想法?谢谢你的帮助

1 个答案:

答案 0 :(得分:17)

像这样写:

.box{
    width:50px;
    height:100px;
    border:1px solid black;
    display:inline-block;
    *dsplay:inline;/* For IE7*/
    *zoom:1;/* For IE7*/
    white-space:normal;
}
#container{
    width:100%;
    height:200px;
    float:left;
    overflow-x:scroll;
    white-space:nowrap;
}

选中此http://jsfiddle.net/z5nEQ/3/

相关问题