Bootstrap 4 Media Objects

Bootstrap 4 Media Objects

Bootstrap 4 offers a media object component that aligns the media objects and the content. The media object is used to create a repetitive and complex component in which media is placed on either side (i.e., either left or right) of the component such as blogs, tweets, comments, etc.

Basic Media Object – The basic media object is used to create a layout that contains media on any one side (either left or right) along with the content.

Steps for creating Media Object

  • Add .media class to the parent element <div>.
  • Add the .media-body class to the child element to add the body.

Note: You need to add margin and padding on your own with the help of spacing utilities.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap 4 Media Object Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

</head>

<body>

<div class="container mt-3">

  <h2>Media Object</h2><br>

  <div class="media border p-3">

    <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" alt="John Williams" class="mr-3 mt-3 rounded-circle" style="width:60px;">

    <div class="media-body">

      <h4>John Williams <small><i>Posted on June 10, 2020</i></small></h4>

      <p>John is a software engineer. He works in a multinational firm. He is specialize in many fields.</p>    

    </div>

  </div>

</div>

</body>

</html>

Output

Bootstrap 4 Media Objects

Nested Media Object – Bootstrap 4 also allows you to create a nested media object. The nested media object mans one media object inside the other. The example of the nested media object is comment thread. To create a nested media object,

  • Add a new .media class to the <div> element.
  • Add the .media-body to the child element.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap 4 Media Object Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

</head>

<body>

<div class="container mt-3">

  <h2>Nested Media Objects</h2>

  <div class="media border p-3">

    <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" alt="John Doe" class="mr-3 mt-3 rounded-circle" style="width:60px;">

    <div class="media-body">

      <h4>John Williams <small><i>Posted on May 22, 2020</i></small></h4>

      <p>John is a software engineer. He works in a multinational firm. He is specialize in many fields.</p>

      <p>He is a very professional engineer and has done so many projects.</p>

      <div class="media p-3">

        <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" alt="Jane Doe" class="mr-3 mt-3 rounded-circle" style="width:45px;">

        <div class="media-body">

          <h4>Jane Williams <small><i>Posted on May 23 2020</i></small></h4>

          <p>John is a software engineer. He works in a multinational firm. He is specialize in many fields.</p>

          <p>He is a very professional engineer and has done so many projects.</p>

        </div>

      </div>

    </div>

  </div>

</div>

</body>

</html>

Output

Bootstrap 4 Media Objects

Right-Aligned Media Object – If you want to create a right-aligned media object, add the image using <img> element before the .media-body.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap 4 Media Object Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

</head>

<body>

<div class="container mt-3">

  <h2>Right Aligned Media Objects</h2><br>

  <div class="media border p-3">

    <div class="media-body">

      <h4>John Williams <small><i>Posted on May 22, 2020</i></small></h4>

      <p>John is a software engineer. He works in a multinational firm. He is specialize in many fields.</p>

      <p>He is a very experienced engineer and has done so many projects.</p>

    </div>

    <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" alt="John Doe" class="mr-3 mt-3 rounded-circle" style="width:60px;">

  </div>

</div>

</body>

</html>

Output

Bootstrap 4 Media Objects

Top, Middle, and Bottom Alignment – You can place the media object anywhere in the component. To place the media object on the top, bottom and middle, add .align-self-* class to the <img> element.

Example

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap 4 Media Object Example</title>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

</head>

<body>

<div class="container mt-3">

  <h2>Media Object</h2>

  <!-- Media top -->

  <div class="media">

    <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" class="align-self-start mr-3" style="width:80px">

    <div class="media-body">

      <h5>Media Top</h5>

      <p>The media object is used to create a repetitive and complex component in which media is placed on any one side (either left or right) of the component such as


blog, tweets, comments, etc.</p>

      <p>You can place media at the top of the component by adding <strong>.align-self-start</strong> class to the <strong>img</strong> element.</p>

    </div>

  </div>

  <!-- Media middle -->

  <div class="media mt-3">

    <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" class="align-self-center mr-3" style="width:80px">

    <div class="media-body">

      <h5>Media Middle</h5>

      <p>The media object is used to create a repetitive and complex component in which media is placed on any one side (either left or right) of the component such as


blog, tweets, comments, etc.</p>

      <p>You can place media in the ceneter of the component by adding <strong>.align-self-center</strong> class to the <strong>img</strong> element.</p>

    </div>

   </div>

  <!-- Media bottom -->

  <div class="media mt-3">

    <img src="https://images.unsplash.com/photo-1543610892-0b1f7e6d8ac1" class="align-self-end mr-3" style="width:80px">

    <div class="media-body">

      <h5>Media Bottom</h5>

      <p>The media object is used to create a repetitive and complex component in which media is placed on any one side (either left or right) of the component such as


blog, tweets, comments, etc.</p>

      <p>You can place media at the bottom of the component by adding <strong>.align-self-end</strong> class to the <strong>img</strong> element.</p>

    </div>

  </div>

  <br>

  <br>

</div>

</body>

</html>

Output

Bootstrap 4 Media Objects

Related Topics

Bootstrap Typography

Bootstrap provides simple and easily customized typography for headings, body text, lists, and many more. Headline <h1> to <h6> By default, Bootstrap has HTML headings (<h1> to <h6>) that are given below: Example <h1>h1. Bootstrap heading</h1>   <h2>h2. Bootstrap heading</h2>   <h3>h3. Bootstrap heading</h3>   <h4>h4. Bootstrap heading</h4>   <h5>h5. Bootstrap heading</h5>   <h6>h6. Bootstrap heading</h6> Try Now ←...

1 minute read.

Bootstrap Pager

← Prev Next → ...

1 minute read.

Bootstrap Tabs and Pills

Bootstrap Menus Bootstrap menu is used to create different types of menu. It can created horizontal with its .list-inlineclass. <div class="container">       <h3>Example of Bootstrap Menu</h3>       <ul class="list-inline">         <li><a href="#">Home</a></li>         <li><a href="#">About</a></li>         <li><a href="#">Contact</a></li>         <li><a href="#">services</a></li>       </ul>     </div> Try Now Bootstrap Tabs Bootstrap tabl is look like is menu but there is some difference....

4 minutes read.

Bootstrap Toast Example

What are toasts? Toasts are similar to notifications, and they are lightweight and act as push notifications from mobile and desktop operating systems. They’re built using flexbox in Bootstrap. They can...

4 minutes read.

Bootstrap Wells

In Bootstrap, well are used to add a rounded border around an element. It is default some padding and gray background color. It is like a container that displays the content....

1 minute read.

CakePHP Layouts & Elements

A layout includes a presentation code that can be wrapped out in your view. It means that what you want to see in your view should be well-positioned in layout. When you create...

9 minutes read.

Bootstrap 4 Tooltip

Bootstrap 4 Tooltip Tooltip Bootstrap 4 offers a tooltip component, a small popup box that appears when you move the cursor over an element such as buttons or any highlighted element. It...

3 minutes read.

Bootstrap 4 Icons

Bootstrap 4 Icons Bootstrap 3 contains the default icon library. But in bootstrap 4, you have to include the external icon library by yourself. Many free icon libraries are available such...

2 minutes read.

Bootstrap Validation Example

Validation We can provide valuable and actionable feedback to the users through an HTML form validation. It happens via custom styles or behaviors of default browsers and JavaScript. How does validation work...

4 minutes read.

Bootstrap 4 Media Objects

Bootstrap 4 Media Objects Bootstrap 4 offers a media object component that aligns the media objects and the content. The media object is used to create a repetitive and complex component...

7 minutes read.

Dropdown & Dropup

Bootstrap Dropdowns The bootstrap dropdown menu is used to create a toggleable menu. It provides users to choose one value from a predefined list. Before creating dropdown menu, we have to know...

3 minutes read.

Bootstrap Input groups

Bootstrap 4 Input groups The input group is a component of Bootstrap 4, which is used to create interactive and stylish form controls. With the help of input groups, you can easily customize the input...

8 minutes read.

Bootstrap 4 Carousel

Bootstrap 4 Carousel Bootstrap 4 offers a carousel component, which is also known as a slider or slideshow. The carousel is used for the dynamic representation of content using images with...

7 minutes read.

Environment Setup

How to use Bootstrap? We can use bootstrap in our project either by downloading or by providing link of the library files. 1) Download Bootstrap files To download files, visit official site of bootstrap www.getbootstrap.com/download/ and...

1 minute read.

Bootstrap 4 Collapse

Bootstrap 4 Collapse Collapse is a bootstrap component that is similar to the dropdown button. Collapse is used to hide or show the content such as paragraphs, sentences, etc.  When we click on a...

4 minutes read.

Bootstrap 4 Margin classes

Bootstrap 4 contains a variety of brief, responsive margin and padding utility classes to change the appearance of an element. The Bootstrap 4 margin classes use for the outer spacing of...

8 minutes read.

Bootstrap 4 Progress Bar

Bootstrap Progress Bar Bootstrap 4 offers progress bars that are used to represent the progress of tasks such as downloading a file, software installation, etc. on the computer. It represents the percentage of the...

9 minutes read.

Difference between Bootstrap and WordPress

What is WordPress? WordPress is a free open-source CMS (Content Management System) that is written using Hypertext Pre-processor (PHP) and is paired with MySQL and is supported with HTTPS (Hypertext Transfer...

3 minutes read.

Bootstrap 4 Scrollspy

Bootstrap 4 Scrollspy Bootstrap 4 offers a scrollspy component that is used to make the website more attractive and eye-catching. Basically, the scrollspy is used on the single-page website. The scrollspy highlights the nav...

5 minutes read.

Bootstrap 4 Alerts

Bootstrap 4 Alerts Bootstrap 4 offers alerts that are used to provide feedback messages on the user’s actions. There is no boundation of text length in the alerts. Alerts can be created...

1 minute read.