html – 滚动叠加div而不滚动整个页面

前端之家收集整理的这篇文章主要介绍了html – 滚动叠加div而不滚动整个页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个主页面上有一些内容.然后我有一个弹出的模态比屏幕本身长,所以我必须滚动才能看到它.我需要做什么才能使我的CSS只进行模态div滚动而不是整个页面

这是模态的CSS

  1. #overlay {
  2. visibility: hidden;
  3. position: absolute;
  4. left: 45%;
  5. width:auto;
  6. border:1px solid #A17E13;
  7. height:auto;
  8. text-align:left;
  9. z-index: 1000;
  10. }
  11. #overlay div {
  12. background-color:#FCFBEC;
  13. }

这是HTML:

  1. <html><body>
  2. <div>main page</div>
  3. <div id="overlay">
  4. <div>
  5. <div>
  6. <asp:Label ID="test">Text for modal here</asp:Label>
  7. </div>
  8. </div>
  9. </div>
  10. </body></html>

解决方法

除了模态div之外,整个页面是不是可滚动的?如果是这样你可以尝试位置:固定;在页面上.模态必须在位置之外:绝对;
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style type="text/css">
  5. #overlay {
  6. /*visibility: hidden;*/
  7. position: fixed;
  8. left: 45%;
  9. width:auto;
  10. border:1px solid #A17E13;
  11. height:900px;
  12. text-align:left;
  13. background-color:orange;
  14. }
  15. .scroller {
  16. height:3000px;
  17. width:400px;
  18. background-color:green;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id="overlay">
  24. this is not moving
  25. </div>
  26.  
  27. <div>
  28. <div class="scroller">
  29. <asp:Label ID="test">This is moving if big enough</asp:Label>
  30. </div>
  31. </div>
  32. </body>
  33. </html>

Fiddle here

猜你在找的HTML相关文章