©
Dokumen ini menggunakan Manual laman web PHP Cina Lepaskan
Bootstrap 媒体对象的文档和示例,构建博客评论,推文等高度重复的组件。
媒体对象有助于建立复杂的和重复的成分,其中一些媒体被定位旁边内容不环绕,所述媒体。另外,Flexbox 只需要两个必需的类。
以下是单个媒体对象的示例。只需要两个类 - 包装.media
和.media-body
你的内容。可选的填充和边距可以通过间隔工具进行控制。
<div class="media"> <img class="mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0">Media heading</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. </div></div>
Internet Explorer 的10-11不会使内联元素类似的链接或图片(或::before
和::after
伪元素)作为柔性物品。唯一的解决方法是设置一个非内联display
的值(例如,block
,inline-block
,或flex
)。我们建议使用.d-flex
我们的显示实用程序之一作为简单的修复。
媒体对象可以无限嵌套,但我们建议您在某个时候停下来。嵌套.media
在.media-body
父媒体对象中的地方。
<div class="media"> <img class="mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0">Media heading</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. <div class="media mt-3"> <a class="pr-3" href="#"> <img src="..." alt="Generic placeholder image"> </a> <div class="media-body"> <h5 class="mt-0">Media heading</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. </div> </div> </div></div>
媒体对象中的媒体可以与 Flexbox 实用程序一起对齐到内容的顶部(默认),中间或结尾.media-body
。
<div class="media"> <img class="align-self-start mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0">Top-aligned media</h5> <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.</p> <p>Donec sed odio dui. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> </div></div>
<div class="media"> <img class="align-self-center mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0">Center-aligned media</h5> <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.</p> <p class="mb-0">Donec sed odio dui. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> </div></div>
<div class="media"> <img class="align-self-end mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0">Bottom-aligned media</h5> <p>Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus.</p> <p class="mb-0">Donec sed odio dui. Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.</p> </div></div>
通过修改HTML本身或通过添加一些自定义 Flexbox CSS 来设置order
属性(以您选择的整数)更改媒体对象中内容的顺序。
<div class="media"> <div class="media-body"> <h5 class="mt-0 mb-1">Media object</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. </div> <img class="ml-3" src="..." alt="Generic placeholder image"></div>
由于媒体对象的结构要求非常少,您还可以在列表 HTML 元素上使用这些类。在你的<ul>
或<ol>
,添加.list-unstyled
删除任何浏览器的默认列表样式,然后申请.media
你<li>
的。与往常一样,在需要的地方使用间隔工具进行微调。
<ul class="list-unstyled"> <li class="media"> <img class="mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0 mb-1">List-based media object</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. </div> </li> <li class="media my-4"> <img class="mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0 mb-1">List-based media object</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. </div> </li> <li class="media"> <img class="mr-3" src="..." alt="Generic placeholder image"> <div class="media-body"> <h5 class="mt-0 mb-1">List-based media object</h5> Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis. Fusce condimentum nunc ac nisi vulputate fringilla. Donec lacinia congue felis in faucibus. </div> </li></ul>