一般情况:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta content="yes" name="apple-mobile-web-app-capable">
        <meta content="yes" name="apple-touch-fullscreen"> 
        <meta content="telephone=no,email=no" name="format-detection"> 
        <title></title>
        <style type="text/css">
            .a {
                width: 500px;
                height: 500px;
                position: fixed;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                background: forestgreen;
                /*overflow: auto;*/
            }
            .c {
                width: 50px;
                height: 1000px;
                background: blue;
            }
            .b {
                width: 50px;
                height: 50px;
                background: red;
                position: absolute;
                left: 0;
                bottom: -50px;
            }
        </style>
    </head>
    <body>
        <div class= "a">
            <div class="c"></div>
            <div class= "b"></div>
        </div>
    </body>
    <script>
          
         
    </script>
</html>

效果:

父元素设置overflow,绝对定位的子元素会被隐藏或一起滚动

过长溢出,绝对定位元素相对父元素位置设置

 

如果将overflow设置为hidden

父元素设置overflow,绝对定位的子元素会被隐藏或一起滚动

过长部分被隐藏,无法滚动,绝对定位元素也被隐藏

 

如果将overflow设为scroll或auto

父元素设置overflow,绝对定位的子元素会被隐藏或一起滚动

出现滚动条,绝对定位元素的位置将相对于父元素的内容位置设置

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-08
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-10-07
  • 2021-12-05
相关资源
相似解决方案