Bootstrap 4教程-Bootstrap 4 Media Objects - 书目录

Bootstrap 4教程-Bootstrap 4 Media Objects

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 class.
Media Object
No special class is needed for the media object (eg, <img>, <video> etc). Just insert it into the HTML where you need it.
Media Body
Apply the .media-body class to the text’s parent <div> or other element. Also apply the .media-heading to any headings inside the media body.
Use a Booststrap spacing utility to apply margins to the media object (for example, mr-3).

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.

Horizontal Alignment

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

Vertical Alignment

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.

Media Lists

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.

To create a media list, apply the .list-unstyled class to the <ul> tag, and the .media class to the <li> tag.



英语原文: 由工具自动翻译,由书目录整理