具有固定的页眉和页脚以及可滚动内容的模态对话框 [英] Modal dialog with fixed header and footer and scrollable content
问题描述
我正在尝试创建一个模态对话框,该对话框具有固定的页眉和页脚,并且模态对话框中的内容(在这种情况下为用户列表)是可滚动的...
I'm trying to create a modal dialog that has an fixed header and footer and that the content (in this case list of users) inside the modal dialog is scrollable...
到目前为止,我最大的努力是在图像上显示了结果:
My best attempt so far gave me the result on the image:
我假设看到图像后,我不必描述问题是什么...而且我还假设您将知道解决方案的外观...:)
I assume that after seeing the image I dont have to describe what the problem is... and I also assume that you will know what the solution has to look like... :)
但是请确保我仍然会写它...模态对话框需要有一个固定的页眉(标题为编辑板",板名"和板类型"所在的区域)和页脚( 保存"按钮所在的区域必须是固定的/不可滚动的...唯一可滚动的是用户列表...
But just to be sure I'll write it anyway... The modal dialog needs to have a fixed header (Area where the title "Edit board" "Board name" and "Board type" are located) and footer (Area where the "SAVE" button is located) haveto be fixed/unscrolable... the only thing that has to be scrollable is the list of users...
代码:
HTML
<div id="addBoardModal" class="modal modal-fixed-footer">
<form class="Boards_new" autocomplete="off">
<div class="modal-header">
<h5>{{title}}</h5>
<div class="input-field">
<!--INPUT FORM-->
<div class="BoadType">
<!--RADIAL BUTTON THING-->
<div class="modal-content">
<div class="shareMembers" style="margin-top:18px;">
<div class="row">
<h5 class="left">Share</h5>
<!--LIST OF USERS !!!THIS HAS TO BE SCROLLABLE!!!-->
</div>
</div>
<div class="modal-footer">
<!--JSUT THIS SAVE BUTTON-->
</div>
CSS:
.modal {
@extend .z-depth-4;
display: none;
position: fixed;
left: 0;
right: 0;
background-color: #fafafa;
padding: 0;
max-height: 70%;
width: 55%;
margin: auto;
//overflow-y: auto;
border-radius: 2px;
will-change: top, opacity;
@media #{$medium-and-down} {
width: 80%; }
h1,h2,h3,h4 {
margin-top: 0; }
.modal-header{
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
width: 100%;
height: 15rem;
padding:24px;
}
.modal-header > .input-field{width:100%;}
.modal-content {
padding: 24px;
position: absolute;
width: 100%;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.modal-close {cursor: pointer;}
.modal-footer {
border-radius: 0 0 2px 2px;
border-top: 1px solid rgba(0, 0, 0, 0.1);
background-color: #fafafa;
padding: 4px 6px;
height: 56px;
width: 100%;
.btn, .btn-flat {
float: right;
margin: 6px 0;
}
}
}
因此,如果有人可以告诉我我的代码在做什么错,或者我是否应该做其他不同的事情,那将是很好的事情...
So if anyone could please tell me what am I doing wrong in my code or if I should be doing something diferently that would be nice...
I used these examples to code this...Example no.1 & Example no.2
注意::我正在使用Materialize框架
NOTE: I'm using the Materialize framework
推荐答案
您可以使用calc()
函数尝试max-height
,例如:
You can try max-height
using calc()
function, like:
.modal-content {
height: auto !important;
max-height: calc(100vh - 340px) !important;
}
看看下面的代码段(使用全屏):
Have a look at the snippet below (use full screen):
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal();
});
.modal {
overflow: hidden;
}
.modal-header {
padding: 15px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}
.modal-header h4 {
margin: 0;
}
.modal-content {
height: auto !important;
max-height: calc(100vh - 340px) !important;
}
.content-row {
display: flex;
align-items: center;
padding: 10px;
border-bottom: 1px solid #ddd;
}
.content-row:last-child {
border-bottom: none;
}
.icon {
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #33b5e5;
color: #fff;
}
.name {
padding: 0 10px;
}
.role {
padding: 0 10px;
flex: 1;
text-align: right;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.css" rel="stylesheet"/>
<!-- Modal Trigger -->
<a class="modal-trigger waves-effect waves-light btn" href="#modal1">Modal</a>
<!-- Modal Structure -->
<div id="modal1" class="modal modal-fixed-footer">
<div class="modal-header">
<h4>Modal Header</h4>
</div>
<div class="modal-content">
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
<div class="content-row">
<div class="icon">1</div>
<div class="name">Name</div>
<div class="role">Role</div>
</div>
</div>
<div class="modal-footer">
<a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat ">Agree</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>
希望这会有所帮助!
这篇关于具有固定的页眉和页脚以及可滚动内容的模态对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!