Bootstrap 4 tutorial

Components (8): Media object / Modal

Media Object

Basic example

48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Nesting

div.media can be nested inside div.media-body

Nesting example

48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Three levels (more levels as the same way)

48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Alignment

Use Flex utilities . Examples for aligning img (with added borders).

img.align-self-start

48x48 placeholder image
Top-aligned media
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

img.align-self-center

48x48 placeholder image
Center-aligned media
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

img.align-self-end

48x48 placeholder image
Bottom-aligned media
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Order

(1) Change DOM element order: move img to the last

Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
48x48 placeholder image

(2) Change order with .order-* of Flex utilities .

48x48 placeholder image
Media heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Media list

Example using ul (same as ol )

Sample: modified to always-displayed (hidden as default)

Modal invocation

Modals can be invoked with buttons.

See the example below (clicking the button show a modal).

Behaviors (summary)

Scrolling long content

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.

Vertically centered

Adding .modal-dialog-centered to div.modal-dialog displays a modal on vertically center.

Tooltops and popovers

Example using a Tooltip and Popovers

Using the grid

Example using Grid (see source for detail).

Varying modal content

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);
});

Optional sizes

Use div.modal-dialog.modal-(xl|lg|sm)