通常狀況:css
<!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>
效果:html
過長溢出,絕對定位元素相對父元素位置設置web
若是將overflow設置爲hiddenapp
過長部分被隱藏,沒法滾動,絕對定位元素也被隱藏spa
若是將overflow設爲scroll或autorest
出現滾動條,絕對定位元素的位置將相對於父元素的內容位置設置!code