모달 바디에만 스크롤 막대를 두는 방법은 무엇입니까?
다음과 같은 요소가 있습니다.
<div class="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="overflow-y: scroll; max-height:85%; margin-top: 50px; margin-bottom:50px;" >
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title"></h3>
</div>
<div class="modal-body"></div>
<div class="modal-footer"></div>
</div>
</div>
</div>
그것은 모달 대화 상자를 다음과 같이 보여줍니다. 기본적으로 스크롤 막대를 전체 주위에 놓고 표시하려는 내용이 포함되어 modal-dialog
있지 않습니다 modal-body
.
이미지는 다음과 같습니다.
스크롤 막대 modal-body
만 어떻게 구합니까?
할당 style="overflow-y: scroll; max-height:85%; margin-top: 50px; margin-bottom:50px;"
을 시도했지만 modal-body
작동하지 않았습니다.
당신은 설정해야 height
의를 .modal-body
에 그것을 제공 overflow-y: auto
. .modal-dialog
오버플로 값 도로 재설정하십시오 initial
.
작업 샘플을 참조하십시오.
http://www.bootply.com/T0yF2ZNTUd
.modal{
display: block !important; /* I added this to see the modal, you don't need this */
}
/* Important part */
.modal-dialog{
overflow-y: initial !important
}
.modal-body{
height: 250px;
overflow-y: auto;
}
IE 9 이상 만 지원하는 경우이 CSS를 사용하여 창 크기에 맞게 조정할 수 있습니다. 머리글 또는 바닥 글의 높이에 따라 "200px"를 조정해야 할 수도 있습니다.
.modal-body{
max-height: calc(100vh - 200px);
overflow-y: auto;
}
@carlos calla와 @jonathan marston 결합 솔루션으로 문제가 해결되었습니다.
/* Important part */
.modal-dialog{
overflow-y: initial !important
}
.modal-body{
max-height: calc(100vh - 200px);
overflow-y: auto;
}
에게 추가 카를로스 칼라 의 훌륭한 대답.
.modal-body의 높이를 설정해야하지만 미디어 쿼리를 사용하여 화면 크기에 적합한 지 확인할 수 있습니다.
.modal-body{
height: 250px;
overflow-y: auto;
}
@media (min-height: 500px) {
.modal-body { height: 400px; }
}
@media (min-height: 800px) {
.modal-body { height: 600px; }
}
옵션 : 모달이 창 높이를 초과하지 않고 .modal-body에서 스크롤 막대를 사용하지 않으려면이 반응 형 솔루션을 사용할 수 있습니다. 실제 데모를 참조하십시오 : http://codepen.io/dimbslmh/full/mKfCc/
function setModalMaxHeight(element) {
this.$element = $(element);
this.$content = this.$element.find('.modal-content');
var borderWidth = this.$content.outerHeight() - this.$content.innerHeight();
var dialogMargin = $(window).width() > 767 ? 60 : 20;
var contentHeight = $(window).height() - (dialogMargin + borderWidth);
var headerHeight = this.$element.find('.modal-header').outerHeight() || 0;
var footerHeight = this.$element.find('.modal-footer').outerHeight() || 0;
var maxHeight = contentHeight - (headerHeight + footerHeight);
this.$content.css({
'overflow': 'hidden'
});
this.$element
.find('.modal-body').css({
'max-height': maxHeight,
'overflow-y': 'auto'
});
}
$('.modal').on('show.bs.modal', function() {
$(this).show();
setModalMaxHeight(this);
});
$(window).resize(function() {
if ($('.modal.in').length != 0) {
setModalMaxHeight($('.modal.in'));
}
});
부트 스트랩 버전> = 4.3
Bootstrap 4.3 added new built-in scroll feature to modals. This makes only the modal-body content scroll if the size of the content would otherwise make the page scroll. To use it, just add the class modal-dialog-scrollable to the same div that has the modal-dialog class.
Here is an example:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalScrollable">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModalScrollable" tabindex="-1" role="dialog" aria-labelledby="exampleModalScrollableTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalScrollableTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
the<br>quick<br>brown<br>fox<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
I know this is an old topic but this may help someone else.
I was able to make the body scroll by making the modal-dialog element position fixed. And since I would never know the exact height of the browser window, I took the information I was sure about, the height of the header and the footer. I was then able to make the modal-body element's top and bottom margins match those heights. This then produced the result I was looking for. I threw together a fiddle to show my work.
also, if you want a full screen dialog just un-comment the width:auto; inside the .modal-dialog.full-screen section.
https://jsfiddle.net/lot224/znrktLej/
And here is the css that I used to modify the bootstrap dialog.
.modal-dialog.full-screen {
position:fixed;
//width:auto; // uncomment to make the width based on the left/right attributes.
margin:auto;
left:0px;
right:0px;
top:0px;
bottom:0px;
}
.modal-dialog.full-screen .modal-content {
position:absolute;
left:10px;
right:10px;
top:10px;
bottom:10px;
}
.modal-dialog.full-screen .modal-content .modal-header {
height:55px; // adjust as needed.
}
.modal-dialog.full-screen .modal-content .modal-body {
overflow-y: auto;
position: absolute;
top: 0;
bottom: 0;
left:0;
right:0;
margin-top: 55px; // .modal-header height
margin-bottom: 80px; // .modal-footer height
}
.modal-dialog.full-screen .modal-content .modal-footer {
height:80px; // adjust as needed.
position:absolute;
bottom:0;
left:0;
right:0;
}
Or simpler you can put between your tags first, then to the css class.
<div style="height: 35px;overflow-y: auto;"> Some text o othre div scroll </div>
#scroll-wrap {
max-height: 50vh;
overflow-y: auto;
}
Using max-height
with vh
as the unit on the modal-body
or a wrapper div inside of the modal-body
. This will resize the height of modal-body
or the wrapping div(in this example) automatically when a user resize the window.
vh
is length unit representing 1% of the viewport size for viewport height.
Browser compatibility chart for vh
unit.
Example: https://jsfiddle.net/q3xwr53f/
A simple js solution to set modal height proportional to body's height :
$(document).ready(function () {
$('head').append('<style type="text/css">.modal .modal-body {max-height: ' + ($('body').height() * .8) + 'px;overflow-y: auto;}.modal-open .modal{overflow-y: hidden !important;}</style>');
});
body's height has to be 100% :
html, body {
height: 100%;
min-height: 100%;
}
모달 바디 높이를 바디의 80 %로 설정했는데, 물론 커스터마이징이 가능합니다.
도움이 되길 바랍니다.
나를 위해 일한 것은 높이를 100 %로 설정하는 것입니다. 자동 희망에 오버플로가 있으면 도움이 될 것입니다.
<div style="height: 100%;overflow-y: auto;"> Some text o othre div scroll </div>
참고 URL : https://stackoverflow.com/questions/25874001/how-to-put-scroll-bar-only-for-modal-body
'development' 카테고리의 다른 글
Visual Studio 2010 용 Qt를 빌드하는 방법 (0) | 2020.06.26 |
---|---|
.htaccess mod_rewrite-재 작성 규칙에서 디렉토리를 제외하는 방법 (0) | 2020.06.25 |
ActiveRecord 콜백을 실행하지 않으려면 어떻게해야합니까? (0) | 2020.06.25 |
컨텐츠 요약 검색을위한 깨끗한 Wikipedia API가 있습니까? (0) | 2020.06.25 |
스 와이프하여 UITableViewCell을 삭제합니다. (0) | 2020.06.25 |