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

时间:2017-05-24 01:29:45

标签: css html5 css3 responsive-design css-position

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

当我点击按钮"创建过程"我无法在灯箱中滚动。

灯箱有一个固定的位置,因为当我使用绝对时,背景会混乱。灯箱是白色背景。

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

&GT;

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

&GT;

 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';
}

1 个答案:

答案 0 :(得分:2)

试试这段代码。这是你追求的吗?

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

我添加了自动溢出功能,因此在较小的屏幕上,灯箱将成为滚动。

请告诉我这是你所追求的。

<强>更新

要仅滚动 #lightbox ,您可以在CSS中添加overflow auto。

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