单个列的CSS使用水平滚动滚动

时间:2016-07-20 02:06:01

标签: html css user-interface stylesheet

我正在构建一个包含信息列的UI组件。每列都需要单独滚动。我之前在SO.com上发现了这个问题,但是我无法将其与其他要求进行协调 - 页面水平滚动以显示不适合屏幕的列。

我有水平滚动工作,但不能让它与单个列滚动一起工作。代码:

#board {
    float: left;
    height: 98%;
    max-height: 98%;
    width: 4300px; /*smaller than columns to force horizontal scroll */
    margin: auto;
    border: none;
    overflow-x: scroll;
}

#columns {
    height: 98%;
    float: left;
    width: 4800px; /* need this much width */
    margin: auto;
    border: none;
    overflow-x:auto;
}

.column {
    float: left;
    padding-bottom: 50px;
    width: 240px;
    height: 100%;
    max-height: 100%;
    padding: 5px;
    padding-bottom: 100px;
    margin-left: 5px;
    overflow-y: auto;
    overflow-x: hidden;
}

<div id="board">
    <div id="columns">
        <div id="col1" class="column">
            <div class="card"> ...content... </div>
            <div class="card"> ...content... </div>
            <div class="card"> ...content... </div>
            <div class="card"> ...content... </div>
        </div>
        <div id="col2" class="column">
            <div class="card"> ...content... </div>
            <div class="card"> ...content... </div>
            <div class="card"> ...content... </div>
            <div class="card"> ...content... </div>
        </div>
        <!-- 12-16 more columns -->
    </div>
</div>

编辑修复html中的id vs class问题。

1 个答案:

答案 0 :(得分:1)

我尝试简化您的代码,仅包含解决问题所需的内容,但它应该有效。你的CSS中也有一些错误:你有#boards的样式,但外容器的类boards不是id,你有#columns的样式但是中间内部容器的id为positions

&#13;
&#13;
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}
.board {
  height: 100%;
  width: 200px;
  overflow-x: scroll;
}
#columns {
  height: 100%;
  width: 500px;
  white-space: nowrap;
}
.column {
  vertical-align: top;
  height: 100%;
  display: inline-block;
  width: 150px;
  overflow-y: auto;
  overflow-x: hidden;
}
.card {
  height: 200px;
  background: #F00;
  margin-bottom: 5px;
}
&#13;
<div class="board">
  <div id="columns">
    <div class="column">
      <div class="card">...content...</div>
      <div class="card">...content...</div>
      <div class="card">...content...</div>
      <div class="card">...content...</div>
    </div>
    <div class="column">
      <div class="card">...content...</div>
      <div class="card">...content...</div>
      <div class="card">...content...</div>
    </div>
    <div class="column">
      <div class="card">...content...</div>
    </div>
&#13;
&#13;
&#13;