如何垂直居中自舉模態?我在這裏尋找解決方案,但他們沒有響應,或者根本沒有工作。我正在使用Bootsrap 3.Bootstrap模態響應垂直居中?
模式不再響應較小的屏幕,或者在使用下面的解決方案後調整瀏覽器窗口大小。
jQuery的,
$('.modal').on('shown.bs.modal', function() {
$(this).find('.modal-dialog').css({
'margin-top': function() {
return -($(this).outerHeight()/2);
},
'margin-left': function() {
return -($(this).outerWidth()/2);
}
});
});
CSS,
.modal-dialog {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
}
引導,
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="false">
<div class="modal-dialog custom-class">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
任何想法?
編輯:
我試圖用這個CSS,
@media screen and (min-width: 768px) {
.custom-class {
width: 800px; /* either % (e.g. 60%) or px (400px) */
top: 25%;
}
}
模態只是回落到較小的屏幕上的默認位置,但我想它垂直居中。
也,top: 25%;
並沒有使它完全垂直居中。
這是什麼意思_The模式不響應了? http://jsfiddle.net/9TL4U/ – Morpheus