固定div内滚动静态div

时间:2017-03-29 18:56:41

标签: css scroll css-position

我有一个元素container必须保持静态。它位于fix里面,我需要在container溢出时修复它并滚动它。

示例:

<div id="container" style="width: 850px; height: 200px; position: static;">
    <div id="fix"></div>
    <div id="otherStuff" style="width: 2000px;"></div>
</div>

我可以使用CSS吗?

1 个答案:

答案 0 :(得分:1)

您可以将要溢出的内容放在包含overflow-x: scroll的元素中,#fix元素将保留在原来的位置。

.overflow {
  overflow-x: scroll;
}
<div id="container" style="width: 850px; height: 200px; position: static;">
  <div id="fix">fix</div>
  <div class="overflow">
    <div id="otherStuff" style="width: 2000px;">otherstuff</div>
  </div>
</div>

相关问题