溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Bootstrap媒體對象的示例分析

發(fā)布時間:2021-08-13 09:53:09 來源:億速云 閱讀:111 作者:小新 欄目:web開發(fā)

小編給大家分享一下Bootstrap媒體對象的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

默認樣式

媒體對象一般是成組出現(xiàn),而一組媒體對象常常包括以下幾個部分:

? 媒體對像的容器:常使用“media”類名表示,用來容納媒體對象的所有內(nèi)容

? 媒體對像的對象:常使用“media-object”表示,就是媒體對象中的對象,常常是圖片

? 媒體對象的主體:常使用“media-body”表示,就是媒體對像中的主體內(nèi)容,可以是任何元素,常常是圖片側(cè)邊內(nèi)容

? 媒體對象的標題:常使用“media-heading”表示,就是用來描述對象的一個標題,此部分可選

除了上面四個部分之外,在Bootstrap框架中還常常使用“media-left”或者“media-right”來控制媒體對象中的對象浮動方式

[注意]在 html 結(jié)構中, .media-right 應當放在 .media-body 的后面

媒體對象樣式相對來說比較簡單,只是設置他們之間的間距

.media,
.media-body {
 overflow: hidden;
 zoom: 1;
}
.media,
.media .media {
 margin-top: 15px;
}
.media:first-child {
 margin-top: 0;
}
.media-object {
 display: block;
}
.media-heading {
 margin: 0 0 5px;
}
.media-left {
 margin-right: 10px;
}
.media-right {
 margin-left: 10px;
}
<div class="media">
  <a class="media-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=100 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>好的代碼像粥一樣,都是用時間熬出來的</div>
  </div>
</div>

Bootstrap媒體對象的示例分析

嵌套

在評論系統(tǒng)中,經(jīng)常會有媒體對象嵌套的需求。在Bootstrap框架中的媒體對象也具備這樣的功能,只需要將另一個媒體對象結(jié)構放置在媒體對象的主體內(nèi)“media-body”

<div class="media">
  <a class="media-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=100 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>好的代碼像粥一樣,都是用時間熬出來的</div>
    <div class="media">
      <a class="pull-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
        <img class="media-object" src="http://via.placeholder.com/100x100" alt="...">
      </a>
      <div class="media-body">
        <h5 class="media-heading">我是小火柴</h5>
        <div>好巧啊,我也叫小火柴</div>
        <div class="media">
          <a class="pull-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
            <img class="media-object" width=100 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
          </a>
          <div class="media-body">
            <h5 class="media-heading">小火柴的藍色理想</h5>
            <div>是的</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="media">
  <a class="media-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=100 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>藍色理想衰落了,前端卻欣欣向榮起來</div>
  </div>
</div>

Bootstrap媒體對象的示例分析

對齊方式

圖片或其他媒體類型可以頂部、中部或底部對齊。默認頂部對齊。通過.media-middle或.media-bottom來設置

.media-middle {
  vertical-align: middle;
}
.media-bottom {
  vertical-align: bottom;
}
<div class="media">
  <a class="media-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=30 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>藍色理想衰落了,前端卻欣欣向榮起來</div>
  </div>
</div>
<div class="media">
  <a class="media-left media-middle" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=30 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>藍色理想衰落了,前端卻欣欣向榮起來</div>
  </div>
</div>
<div class="media">
  <a class="media-left media-bottom" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=30 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>藍色理想衰落了,前端卻欣欣向榮起來</div>
  </div>
</div>

Bootstrap媒體對象的示例分析

媒體對象列表

媒體對象的嵌套僅是媒體對象中一個簡單應用效果之一,在很多時候,我們還會碰到一個列表,每個列表項都和媒體對象長得差不多。Bootstrap框架提供了一個列表展示的效果,在寫結(jié)構的時候可以使用ul,并且在ul上添加類名“media-list”,而在li上使用“media”

媒體對象列表,在樣式上也并沒有做過多的特殊處理,只是把列表的左間距置0以及去掉了項目列表符號

.media-list {
 padding-left: 0;
 list-style: none;
}
<ul class="media-list">
 <li class="media">
  <a class="media-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=30 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>藍色理想衰落了,前端卻欣欣向榮起來</div>
  </div>
 </li>
 <li class="media">
  <a class="media-left" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    <img class="media-object" width=30 src="//img.jbzj.com/file_images/article/201707/huochai.jpg" alt="...">
  </a>
  <div class="media-body">
    <h5 class="media-heading">小火柴的藍色理想</h5>
    <div>好的代碼像粥一樣,都是用時間熬出來的</div>
  </div>
 </li> 
</ul>

Bootstrap媒體對象的示例分析

以上是“Bootstrap媒體對象的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI