1.当您不知道模态的确切高度时,如何将模态垂直放置在中心?
要使Bootstrap 3 Modal绝对居中而不声明高度,您首先需要通过将Bootstrap 3 Modal添加到样式表中来覆盖Bootstrap CSS:
.modal-dialog-center { /* Edited classname 10/03/2014 */
    margin: 0;
    position: absolute;
    top: 50%;
    left: 50%;
}
这会将模态对话框的左上角放置在窗口的中心。
我们必须添加此媒体查询,否则在小型设备上,模式左边距错误:
@media (max-width: 767px) {
  .modal-dialog-center { /* Edited classname 10/03/2014 */
    width: 100%;
  }
} 
现在,我们需要使用JavaScript调整其位置。为此,我们给该元素一个负的顶部和左侧边距,等于其高度和宽度的一半。在本示例中,我们将使用jQuery,因为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);
        }
    });
});
更新(2015年1月10日):
加上Finik的答案。归功于以未知为中心。
.modal {
  text-align: center;
  padding: 0!important;
}
.modal:before {
  content: '';
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  margin-right: -4px; /* Adjusts for spacing */
}
.modal-dialog {
  display: inline-block;
  text-align: left;
  vertical-align: middle;
}
注意负边距吗?这将删除inline-block添加的空间。该空间导致模式跳转到页面底部@media width <768px。
2.是否可以使模态居中并在模态主体中具有overflow:auto,但前提是模态超过屏幕高度?
这可以通过为模体提供溢出y:auto和最大高度来实现。要使其正常工作,这需要花费更多的工作。首先将其添加到样式表中:
.modal-body {
    overflow-y: auto;
}
.modal-footer {
    margin-top: 0;
}
我们将再次使用jQuery获取窗口高度并首先设置模态内容的最大高度。然后,我们必须通过使用modal-header和modal-footer减去modal-content来设置modal-body的最大高度:
$('.modal').on('shown.bs.modal', function() {
    var contentHeight = $(window).height() - 60;
    var headerHeight = $(this).find('.modal-header').outerHeight() || 2;
    var footerHeight = $(this).find('.modal-footer').outerHeight() || 2;
    $(this).find('.modal-content').css({
        'max-height': function () {
            return contentHeight;
        }
    });
    $(this).find('.modal-body').css({
        'max-height': function () {
            return (contentHeight - (headerHeight + footerHeight));
        }
    });
    $(this).find('.modal-dialog').css({
        'margin-top': function () {
            return -($(this).outerHeight() / 2);
        },
        'margin-left': function () {
            return -($(this).outerWidth() / 2);
        }
    });
});
您可以在此处通过Bootstrap 3.0.3找到有效的演示:http : //cdpn.io/GwvrJ 
编辑:建议使用更新的版本,而不是响应更快的解决方案:http : //cdpn.io/mKfCc
更新(30/11/2015):
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() < 768 ? 20 : 60;
  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'));
  }
});
(使用上述编辑功能于2015年11月30日http://cdpn.io/mKfCc更新)