Float media to the right or left of content with Bootstrap’s media object component.
Bootstrap’s media object component provides an easy way to align text and media objects when presenting them alongside each other. It allows you to quickly and easily float media to the left and/or right of a content block. Useful for UI components such as blog comments, Tweets, etc.
How to Use
To use the media object component, you need to apply a class for the outer container, as well as separate classes to the media and to the text.
- Outer Container
- Wrap the whole thing in a
<div>and give it the
- Media Object
- No special class is needed for the media object (eg,
<video>etc). Just insert it into the HTML where you need it.
- Media Body
- Apply the
.media-bodyclass to the text’s parent
<div>or other element. Also apply the
.media-headingto any headings inside the media body.
- Use a Booststrap spacing utility to apply margins to the media object (for example,
Nested Media Objects
You can nest media objects inside each other (i.e. the whole media block). The nested media block will be indented by default.
You can swap the position of the media object and media body in your markup (so that the heading and text come before the image).
Media objects are top-aligned by default. You can change this with any of the flexbox utility classes. For example, to align to the middle, use
d-flex align-self-center. The
d-flex part ensures that
display: flex is applied to the element.
Two Media Objects
You can place more than one image into a media block.
Left & Right Aligned
You can have two media objects appear within a media block — one to the left and one to the right. The media body will need to be inserted between them in the markup.
You can create a media list by placing media objects inside a list. Media lists can be useful for presenting user comment threads, article lists, etc.