Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Bootstrap4 Media Objects

Bootstrap4 Media Objects

Bootstrap provides a great way to handle the layout of media objects (images or videos) and content. Application scenarios include blog comments, microblogs, etc.:

Basic Media Object

To create a media object, add the .media class to the container element, then place the media content in a child container. The child container needs the .media-body class, and then you can add margins, padding, and other effects:

Example

<div class=">

media border p-3

"

<img src="mobile-icon.png" alt=">

John Doe

"

class

=

"

mr-3 mt-3 rounded-circle

"

style

=

"

width:60px;

"

<div class="media-body">
<h4>

Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

div

div

Try it »


Nested Media Objects

Media objects can be nested multiple times (one media object contains another media object)

To nest media objects, you can place a new .media container inside the .media-body container:

Example

<div class=">

media border p-3

"

<img src="mobile-icon.png" alt=">

John Doe

"

class

=

"

mr-3 mt-3 rounded-circle

"

style

=

"

width:60px;

"

<div class="media-body">
<h4>

Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

<div class=">

media p-3

"

<img src="mobile-icon.png" alt=">

Jane Doe

"

class

=

"

mr-3 mt-3 rounded-circle

"

style

=

"

width:45px;

"

<div class="media-body">
<h4>

Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

div

div

div

div

Try it »


Media Object Image Displayed on the Right

If you want to display the avatar image on the right, you can add the image after the .media-body container:

Example

<div class=">

media border p-3

"

<div class="media-body">
<h4>

Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

div

<img src="mobile-icon.png" alt=">

John Doe

"

class

=

"

ml-3 mt-3 rounded-circle

"

style

=

"

width:60px;

"

div

Try it »


Positioning Media Images

We can use the align-self-* related classes to set the display position of the media object image:

Example

<div class="media">
<img src="https://static.jyshare.com/images/mobile-icon.png" class=">

align-self-start mr-3

"

style

=

"

width:60px

"

<div class="media-body">
<h4>

Header -- Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

div

div

<div class="media">
<img src="https://static.jyshare.com/images/mobile-icon.png" class=">

align-self-center mr-3

"

style

=

"

width:60px

"

<div class="media-body">
<h4>

Center -- Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

div

div

<div class="media">
<img src="https://static.jyshare.com/images/mobile-icon.png" class=">

align-self-end mr-3

"

style

=

"

width:60px

"

<div class="media-body">
<h4>

Bottom -- Runoob Tutorial

h4

<

p

What you learn is not just technology, but also dreams!!!

p

div

div

Try it »