From b1623c44290b414b656bb4d9e3baaaa3093bda8f Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Sun, 29 Oct 2017 15:14:10 -0700 Subject: [PATCH] Add `.modal-dialog-centered` for optional vertically centered modal (#24510) * Add .modal-dialog-centered for optional vertically cenetered modal Fixes #23638 * adds modal-dialog-centered class to docs and removes margin to avoid generating a vertical scrolling * mention limitations * fix aria attr * Add `width: 100%` to the .modal-content for the centered version. Adding it here to avoid adding another selector by limiting it to the centered modal modifier. --- docs/4.0/components/modal.md | 58 ++++++++++++++++++++++++++++++++++++ scss/_modal.scss | 15 ++++++++++ 2 files changed, 73 insertions(+) diff --git a/docs/4.0/components/modal.md b/docs/4.0/components/modal.md index c4191b83d1..b9ebc4ad4b 100644 --- a/docs/4.0/components/modal.md +++ b/docs/4.0/components/modal.md @@ -208,6 +208,64 @@ When modals become too long for the user's viewport or device, they scroll indep {% endhighlight %} +### Vertically centered + +Add `.modal-dialog-centered` to `.modal-dialog` to vertically center the modal. **Do not use this with long modals**—it will overflow the viewport and potentially hide parts of your modal. + + + +
+ +
+ +{% highlight html %} + + + + + +{% endhighlight %} + ### Tooltips and popovers [Tooltips]({{ site.baseurl }}/docs/{{ site.docs_version }}/components/tooltips/) and [popovers]({{ site.baseurl }}/docs/{{ site.docs_version }}/components/popovers/) can be placed within modals as needed. When modals are closed, any tooltips and popovers within are also automatically dismissed. diff --git a/scss/_modal.scss b/scss/_modal.scss index 5fabc83f46..bd4abc7c64 100644 --- a/scss/_modal.scss +++ b/scss/_modal.scss @@ -50,11 +50,20 @@ } } +.modal-dialog-centered { + display: flex; + align-items: center; + height: 100%; + margin-top: 0; + margin-bottom: 0; +} + // Actual modal .modal-content { position: relative; display: flex; flex-direction: column; + width: 100%; // Ensure `.modal-content` extends the full width of the parent `.modal-dialog` // counteract the pointer-events: none; in the .modal-dialog pointer-events: auto; background-color: $modal-content-bg; @@ -144,11 +153,17 @@ margin: $modal-dialog-margin-y-sm-up auto; } + .modal-dialog-centered { + margin-top: 0; + margin-bottom: 0; + } + .modal-content { @include box-shadow($modal-content-box-shadow-sm-up); } .modal-sm { max-width: $modal-sm; } + } @include media-breakpoint-up(lg) {