[英]Modal Window with scroll bar
So, I have a modal window in a website that I'm devloping. 因此,我正在开发一个网站中的模式窗口。
The modal is made out of pure CSS, to open it and close it I have javascript functions wich change the css elements to make the modal show/hide. 模态由纯CSS制成,要打开和关闭模态,我有javascript函数,可以更改css元素以使模态显示/隐藏。
CSS of the modal: 模态的CSS:
<style>
.modalDialog {
position: fixed;
font-family: Arial, Helvetica, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog > div {
position: relative;
margin: 10% auto;
padding: 5px 20px 13px 20px;
border-radius: 10px;
background:white;
display: table;
}
.close {
background: #606061;
color: #FFFFFF;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
-moz-box-shadow: 1px 1px 3px #000;
-webkit-box-shadow: 1px 1px 3px #000;
box-shadow: 1px 1px 3px #000;
}
.close:hover {
background: #00d9ff;
}
.btnEncomendarProduto {
background-color:#D60E12;
color:white;
border-radius:5px;
font-size: 12px;
white-space:normal;
cursor:pointer;
text-transform: initial;
border:1px solid #D60E12;
margin-top:3px;
}
</style>
So the problem is when I have a something that displays too much information on the modal, this happens: 所以问题是当我的东西在模态上显示太多信息时,就会发生这种情况:
So I think I need a scroll bar on the div inside the modal. 所以我想我需要在模式内部的div上使用滚动条。 How can I do that?
我怎样才能做到这一点?
Thank you. 谢谢。
If you have an inner div that expands with the content of the actual modal, you can set the max-height
of that div to be something--like 75vh
--and add overflow-y: auto
to that container, and it will automatically add a scrollbar when the content gets longer than that set max-height
. 如果您有一个内部div随实际模态的内容扩展,则可以将该div的
max-height
设置为75vh
类的75vh
并向该容器添加overflow-y: auto
,它将自动当内容的长度超过设置的max-height
时,添加滚动条。
HTML 的HTML
<div class="Content">
<p>
This is the page contents.
</p>
</div>
<div class="Modal" id="modal">
<div class="Contents">
<h1>Modal</h1>
<p id="text-area">
[large amounts of content]
</p>
</div>
</div>
CSS 的CSS
body
{
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
.Content
{
position: relative;
width: 100%;
}
.Modal
{
position: fixed;
display: none;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.3); // light grey background
}
.Modal.Open
{
display: block;
}
.Modal .Contents
{
overflow-y: auto;
display: block;
position: relative;
width: 90%;
margin: 5% auto 0;
max-height: 90vh;
padding: 5px;
background: #fff;
}
Note the .Modal .Contents
selector and how it works. 请注意
.Modal .Contents
选择器及其工作方式。
JSFiddle Example: https://jsfiddle.net/nj6r0sjw/ JSFiddle示例: https ://jsfiddle.net/nj6r0sjw/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.