Components (8): Media object / Modal
div.media
img
Attributes
.mr-3
(keeps 1rem between media body on right ⇒ Spacing utilities )href="..."
alt="..."
div.media-body
h5
Media heading
Lorem ipsum ...
div.media
can be nested inside div.media-body
Nesting example
Three levels (more levels as the same way)
Use Flex utilities . Examples for aligning img
(with added borders).
img.align-self-start
img.align-self-center
img.align-self-end
(1) Change DOM element order: move img
to the last
(2) Change order with .order-*
of Flex utilities .
Example using ul
(same as ol
)
ul.list-unstyled
.list-unstyled
(⇒ Lists - Unstyled )li.media.my-3
.my-3
(⇒ Spacing utilities )Sample: modified to always-displayed (hidden as default)
div.modal
Attributes
.fade
(does not slides down if removed)id="{modal-id}"
(required for invocation)tabindex="-1"
(removes from tab stops)role="dialog"
aria-labelledby="{label-id}"
aria-hidden="true"
div.modal-dialog
Attribute
role="document"
div.modal-content
div.modal-header
h5.modal-title
Attribute
id="{label-id}"
Modal title
button.close
Attributes
type="button"
data-dismiss="modal"
aria-label="Close"
span
Attribute
aria-hidden="true"
×
div.modal-body
p
Modal body text goes here.
div.modal-footer
button.btn.btn-secondary
Attributes
type="button"
data-dismiss="modal"
Close
button.btn.btn-primary
Attribute
type="button"
Save changes
mixin
templates (see source ).
Modals can be invoked with buttons.
button.btn.(btn-primary|...)
Following attibutes are required
type="button"
data-toggle="modal"
data-target="#{modal-id}"
Launch demo modal
See the example below (clicking the button show a modal).
data-target
accepts arbitrary CSS selector. It is possible to use an any selector to query mutiple elements invokes only the first one. Furthermore, nested modal invocations are not supported.1040
)1050
).fade
, uses CSS animation on showing modal (slides down from top)When modal height is greater than viewport size, the vertical scroll bar is shown at the right. The scroll bar scrolls the modal (not background contents). Check with the demo below.
Adding .modal-dialog-centered
to div.modal-dialog
displays a modal on vertically center.
Example using a Tooltip and Popovers
Example using Grid (see source for detail).
Example below is a demo for displaying button(recipient)-dependent contents to the same modal using JavaScript.
$('#examplemodal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget);
var recipient = button.data('whatever');
var modal = $(this);
modal.find('.modal-title').text('New message to ' + recipient);
modal.find('.modal-body input').val(recipient);
});
data-whatever="@mdo"
show.bs.modal
: see Events for the difference of following two events
show.bs.modal
(used here) On modal triggered (not yet displayed)shown.bs.modal
On modal displayedevent.relatedTarget
data-whatever
to variable recipient
recipient
to the modal title and the element input
Use div.modal-dialog.modal-(xl|lg|sm)