gpt4 book ai didi

html - 垂直居中 modal-lg Bootstrap Modal 使其变小

转载 作者:可可西里 更新时间:2023-11-01 13:47:51 24 4
gpt4 key购买 nike

我将 modal-lg 类用于大型模态,但是当我使用 this SO answer 时垂直居中我的模态它使模态变小:

enter image description here

这种垂直居中导致它变小

.modal {
text-align: center;
}

@media screen and (min-width: 768px) {
.modal:before {
display: inline-block;
vertical-align: middle;
content: " ";
height: 100%;
}
}

.modal-dialog {
display: inline-block;
text-align: left;
vertical-align: middle;
}

html:

<div class="modal fade" id="result-details-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 id="result-details-title" class="modal-title"></h4>
</div>
<div class="modal-body">
...
</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>

当它垂直居中时,如何保持它的大?

最佳答案

如果 CSS 导致您的模态框出现收缩问题,您可以使用这个小的 jQuery 函数执行此操作。

代码片段

 $(function() {
function reposition() {
var modal = $(this),
dialog = modal.find('.modal-dialog');
modal.css('display', 'block');

// Dividing by two centers the modal exactly, but dividing by three
// or four works better for larger screens.
dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
dialog.css("margin-left", Math.max(0, ($(window).width() - dialog.width()) / 2));
}
// Reposition when a modal is shown
$('.modal').on('show.bs.modal', reposition);
// Reposition when the window is resized
$(window).on('resize', function() {
$('.modal:visible').each(reposition);
});
});
.center {
margin-top: 50px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div class="center">
<button data-toggle="modal" data-target="#result-details-modal" class="btn btn-primary center-block">Click Me</button>
</div>

<div class="modal fade" id="result-details-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h4 id="result-details-title" class="modal-title"></h4>
</div>
<div class="modal-body">
...
</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>

关于html - 垂直居中 modal-lg Bootstrap Modal 使其变小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39483301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com