Twitter bootstrap Twitter引导-中心模式对话框 我试图在屏幕中央放置一个等待屏幕模式对话框。这是我试图更改的模式对话框:。如何将其水平和垂直居中?
这只是将一些CSS应用于Twitter bootstrap Twitter引导-中心模式对话框 我试图在屏幕中央放置一个等待屏幕模式对话框。这是我试图更改的模式对话框:。如何将其水平和垂直居中?,twitter-bootstrap,modal-dialog,Twitter Bootstrap,Modal Dialog,这只是将一些CSS应用于pleaseWaitDialogID的问题。您必须设置位置:绝对,并且边距顶部和边距左侧需要是高度和宽度的一半。因此,您的CSS应该如下所示: #pleaseWaitDialog { width: 400px; height: 50px; position: absolute; top: 50%; left: 50%; margin-top: -25px; margin-left: -200px; paddi
pleaseWaitDialog
ID的问题。您必须设置位置:绝对,并且边距顶部和边距左侧需要是高度和宽度的一半。因此,您的CSS应该如下所示:
#pleaseWaitDialog {
width: 400px;
height: 50px;
position: absolute;
top: 50%;
left: 50%;
margin-top: -25px;
margin-left: -200px;
padding: 20px;
}
您需要使用数字,以获得适合您需要的方框大小,但这应该是您的开始。这里有另一个建议,它不涉及页边空白的硬编码。它使用Angular,但您可以用$替换元素。它为边距设置动画,模拟引导中的“淡入”类
var resize = function () {
var dialog = angular.element('#globalPleaseWaitDialog .modal-dialog');
dialog.css('margin-top', (angular.element(that.$window).height() - dialog.height()) / 2 - parseInt(dialog.css('padding-top')));
};
var animate = function () {
var dialog = angular.element('#globalPleaseWaitDialog .modal-dialog');
dialog.animate({ 'margin-top': (angular.element(that.$window).height() - dialog.height()) / 2 - parseInt(dialog.css('padding-top')) }, 'slow');
pleaseWaitDiv.off('shown.bs.modal', animate);
};
this.showPleaseWait = function () {
angular.element($window).on('resize', resize);
pleaseWaitDiv.on('shown.bs.modal', animate);
pleaseWaitDiv.modal();
};
this.hidePleaseWait = function () {
pleaseWaitDiv.modal('hide');
angular.element($window).off('resize', resize);
};
对于我使用的标准jQuery/Coffeescript:
modal = $('.modal')
modal.css 'margin-top', ($(window).height() - modal.height()) / 2 - parseInt(modal.css('padding-top'))
所有的功劳都归功于Sergey Barskiy。我知道有点晚了,但我找到了解决所有问题的方法,将引导模式与标准模式(1)的高度不同
我在Angular的UI引导模式中尝试显示图像(任意大小)时遇到了这样的问题
我在对话框div“modal”中添加了额外的类名“width auto”。
(在我的例子中,它是在“windowClass”参数的帮助下完成的)
我已经编写了SCSS代码:
.自动宽度{
&.莫代尔{
文本对齐:居中;
}
.modal对话框,.modal内容{
显示:内联块;
宽度:自动;
最大宽度:99vw;
溢出:隐藏;
}
}
它解决了这个问题。这是可行的。对于其他有相同问题的人,我删除了高度和位置属性,并将边距顶部更改为-90px。因此,这对我不起作用,我提出了自己的解决方案:(以防万一,这对其他人也不起作用)其中一个更完美!这很好,但是如果用户已经向下滚动了足够多。将看不到模式。您可以通过修改边距顶部来考虑用户的滚动量:dialog.css(“边距顶部”,Math.max(0,($(window.scrollTop())+($(window.height()-dialog.height())/2))
使用负边距时,会导致模式窗口脱离屏幕。删除负号会使其处于低位。
$("#yourModal").modal('show').css({
'margin-top': function () { //vertical centering
return -($(this).height() / 2);
},
'margin-left': function () { //Horizontal centering
return -($(this).width() / 2);
}
});