Bootstrap 4 多媒体对象

Bootstrap 提供了很好的方式来处理多媒体对象(图片或视频)和内容的布局。应用场景有博客评论、微博等:

基础多媒体对象 要创建一个多媒体对象,可以在容器元素上添加 .media 类,然后将多媒体内容放到子容器上,子容器需要添加 .media-body 类,然后添加外边距,内边距等效果:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h2>多媒体对象</h2>
  <p>使用 .media 和 .media-body 类创建多媒体对象:</p>
  <div class="media border p-3">
    <img src="https://static.runoob.com/images/mobile-icon.png" alt="John Doe" class="mr-3 mt-3 rounded-circle" style="width:60px;">
    <div class="media-body">
      <h4>菜鸟教程</h4>
      <p>学的不仅是技术,更是梦想!!!</p>      
    </div>
  </div>
</div>

</body>
</html>

在这里插入图片描述

多媒体对象嵌套 多媒体对象可以多个嵌套(一个多媒体对象中包含另外一个多媒体对象) 要嵌套多媒体对象,可以把新的 .media 容器放到 .media-body 容器中:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h2>多媒体对象嵌套</h2>
  <p>多媒体对象可以多个嵌套(一个多媒体对象中包含另外一个多媒体对象):</p><br>
  <div class="media border p-3">
    <img src="https://static.runoob.com/images/mobile-icon.png" alt="John Doe" class="mr-3 mt-3 rounded-circle" style="width:60px;">
    <div class="media-body">
      <h4>菜鸟教程</h4>
      <p>学的不仅是技术,更是梦想!!!</p>
      <div class="media p-3">
        <img src="https://static.runoob.com/images/mobile-icon.png" alt="Jane Doe" class="mr-3 mt-3 rounded-circle" style="width:45px;">
        <div class="media-body">
          <h4>菜鸟教程</h4>
          <p>学的不仅是技术,更是梦想!!!</p>
        </div>
      </div>  
    </div>
  </div>
</div>

</body>
</html>

在这里插入图片描述

多媒体对象图片显示在右边 如果你想将头像图片显示在右侧,可以在 .media-body 容器后添加图片:

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h2>图片显示在右边</h2>
  <p>如果你想将头像图片显示在右侧,可以在 .media-body 容器后添加图片:</p>
  <div class="media border p-3">
    <div class="media-body">
      <h4>菜鸟教程</h4>
      <p>学的不仅是技术,更是梦想!!!</p>      
    </div>
    <img src="https://static.runoob.com/images/mobile-icon.png" alt="John Doe" class="ml-3 mt-3 rounded-circle" style="width:60px;">
  </div>
</div>

</body>
</html>

在这里插入图片描述

定位多媒体图片位置 我们可以使用 align-self- 相关类来设置多媒体对象的图片显示位置:*

<!DOCTYPE html>
<html>
<head>
  <title>Bootstrap 实例</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container mt-3">
  <h2>多媒体对象</h2>
  <p>我们可以使用 align-self-* 相关类来设置多媒体对象的图片显示位置:</p><br>
  <!-- 头部 -->
  <div class="media">
    <img src="https://static.runoob.com/images/mobile-icon.png" class="align-self-start mr-3" style="width:60px">
    <div class="media-body">
      <h4>头部 -- 菜鸟教程</h4>
      <p>学的不仅是技术,更是梦想!!
      <p>学的不仅是技术,更是梦想!!
      <p>学的不仅是技术,更是梦想!!
    </div>
  </div>

  <!-- 居中 -->
  <div class="media mt-3">
    <img src="https://static.runoob.com/images/mobile-icon.png" class="align-self-center mr-3" style="width:60px">
    <div class="media-body">
      <h4>居中 -- 菜鸟教程</h4>
      <p>学的不仅是技术,更是梦想!!
      <p>学的不仅是技术,更是梦想!!
      <p>学的不仅是技术,更是梦想!!
    </div>
   </div>

  <!-- 底部 -->
  <div class="media mt-3">
    <img src="https://static.runoob.com/images/mobile-icon.png" class="align-self-end mr-3" style="width:60px">
    <div class="media-body">
      <h4>底部 -- 菜鸟教程</h4>
      <p>学的不仅是技术,更是梦想!!
      <p>学的不仅是技术,更是梦想!!
      <p>学的不仅是技术,更是梦想!!
    </div>
  </div>
</div>

</body>
</html>

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值