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 4 Flex

Bootstrap 4 Flex Flex is a Bootstrap 4 component used to manage the layout, navigation bar, grid columns, sizing, alignment, and other components. The flexbox or flex utility is the replacement...

26 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.

Bootstrap Datepicker

What is a Bootstrap Datepicker? It is used to display a calendar with the date, month, and time from a dropdown menu. We will use an example to see how the date...

5 minutes read.

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 Panels

A bootstrap panel is used to create bordered box with some padding around its content. It is created with the .panels classes, and .panel-body classes. There are following classes of the panel: Panel header Panel...

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 Inputs

Bootstrap Inputs Bootstrap Form Inputs – Several pre-defined input types are available in HTML and Bootstrap. These input types help in styling the forms. When an input type is specified in the form, it means...

10 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.

Text Shadows in CSS

Text shadows are created with the text-shadow CSS property. It takes a list of shadows separated by commas to be applied to the text and any of its styles. Each...

5 minutes read.

Bootstrap 4 Content

Typography Typography is used for styling and formatting the content. It also helps in creating customized headings, sub-headings, lists, paragraphs, etc. Headings Bootstrap 4 offers HTML heading <h1> to <h6> that has bolder...

8 minutes read.

Bootstrap Multiselect Dropdown

What is a multi-select Dropdown? Multi-select dropdown lists are used when we want to select multiple options for a particular record. Usually, dropdown lists provide the feature of choosing just one value...

4 minutes read.

Bootstrap 4 Form

Bootstrap 4 Forms Bootstrap 4 provides forms, which are one of the essential components for web pages and web applications. It is an input-based component, used to collect user data with the help of...

8 minutes read.

Bootstrap 4 Toast

Bootstrap 4 Toast Bootstrap 4 offers a Toast component, which is quite similar to the alert box and pushes notifications. The toast is visible on the screen for a few seconds when any...

5 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 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.

Bootstrap 4 Jumbotron

Bootstrap 4 Jumbotron Bootstrap offers Jumbotron, which is used to get more attention to specific content or information on the web page. It provides a gray background-color to the content to make that content...

2 minutes read.

Bootstrap Time Picker Example

What is a Bootstrap Time picker? It is used to display the time in hours, minutes and seconds from a dropdown menu. In this section, we will create an example to...

4 minutes read.

Bootstrap 4 Utilities

Bootstrap 4 Utilities Bootstrap 4 utilities also known as helper classes that are used to add more style to the components. Utilities are used to make the website or webpage more stylish or elegant....

10 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 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.