提问: css 给容器添加overflow: auto;出现滚动条但无法滚动?

找到问题了,是该容器的一个父元素的z-index为负

这个父容器的样式:

    height: 250px;
    box-sizing: border-box;
    border-bottom: 1px solid #000;
    background-color: #eee;
    overflow: auto;
    scroll-snap-type: y mandatory;
    position: relative;
    z-index: 99;

页面中出现了滚动条,但是无法滚动
image.png

阅读 3.8k
2 个回答
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div class="box">
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
    <div>123</div>
  </div>

  <style>
    .box {
      height: 150px;
      box-sizing: border-box;
      border-bottom: 1px solid #000;
      background-color: #eee;
      overflow: auto;
      scroll-snap-type: y mandatory;
      position: relative;
      z-index: 99;
    }
  </style>
</body>

</html>

我这是可以滚动的

未出现上述问题
image.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题