html - 如何制作可滚动的弹出框?

标签 html css responsive-design css-position

https://codepen.io/anon/pen/dWaWor

当我单击“创建过程”按钮时,我无法在灯箱中滚动。

灯箱有一个固定的位置,因为当我使用 absolute 时,背景会乱七八糟。灯箱是白色背景。

<section id="lightbox">
   <i id="x" class="fa fa-times-circle"aria-hidden="true"></i>
   <p class="large">hi</p>
</section>

>

#lightbox {
  height:100%;
  width:100%;
  display: none;
  position: fixed;
  top:0;
  left:0;
  background: #fff;
  z-index:1;
}

>

 var btn_process = document.getElementById('creation-process');
 var lightbox = document.getElementById('lightbox');
 var x = document.getElementById('x');

 btn_process.onclick = function () {
    lightbox.style.display = 'block';
};

x.onclick = function () {
    lightbox.style.display = 'none';
}

最佳答案

试试这段代码。这就是你想要的吗?

#lightbox {
    height: 80%;
    width: 80%;
    display: none;
    position: fixed;
    top: 6%;
    left: 10%;
    background: #fff;
    z-index: 1;
    overflow:auto;
}

我添加了 overflow auto,所以在较小的屏幕上,灯箱将是一个滚动条。

如果这就是您想要的,请告诉我。

更新:

要仅在 #lightbox 上滚动,则可以向 CSS 添加自动溢出。

#lightbox {
    height:100%;
    width:100%;
    display: none;
    position: fixed;
    top: 0%;
    left: 0%;
    background: #fff;
    z-index: 1;
    overflow:auto;
}

关于html - 如何制作可滚动的弹出框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44147516/

相关文章:

html - 无法更改当前链接颜色和背景

javascript - 我需要帮助使用 Flexbox 填充 100% 的计算机屏幕高度

android - 三星 Galaxy S III 上的 CSS @media 查询

css - nth-child "collisions"响应式设计/创建流体网格

jquery - 有没有人见过会动态调整其大小的 jQuery 水平导航菜单?

java - Play Framework : How do I get querystring value inside html template file

javascript - 停止动画并在悬停时将所有圆圈对齐在同一条线上

jquery - 在 jquery 中纠正我

html - 如何在工具栏上同时添加图像和文本而不溢出

html - 包装器内的全 Angular 子 DIV