老生常談Bootstrap媒體對(duì)象
前面的話(huà)
在Web頁(yè)面或者說(shuō)移動(dòng)頁(yè)面制作中,常??吹綀D文混排效果,圖片居左(或居右),內(nèi)容居右(或居左)排列。常常把這樣的效果稱(chēng)為媒體對(duì)象??梢哉f(shuō)它是一種抽象的樣式,可以用來(lái)構(gòu)建不同類(lèi)型的組件。本文將詳細(xì)介紹Bootstrap媒體對(duì)象
默認(rèn)樣式
媒體對(duì)象一般是成組出現(xiàn),而一組媒體對(duì)象常常包括以下幾個(gè)部分:
☑ 媒體對(duì)像的容器:常使用“media”類(lèi)名表示,用來(lái)容納媒體對(duì)象的所有內(nèi)容
☑ 媒體對(duì)像的對(duì)象:常使用“media-object”表示,就是媒體對(duì)象中的對(duì)象,常常是圖片
☑ 媒體對(duì)象的主體:常使用“media-body”表示,就是媒體對(duì)像中的主體內(nèi)容,可以是任何元素,常常是圖片側(cè)邊內(nèi)容
☑ 媒體對(duì)象的標(biāo)題:常使用“media-heading”表示,就是用來(lái)描述對(duì)象的一個(gè)標(biāo)題,此部分可選
除了上面四個(gè)部分之外,在Bootstrap框架中還常常使用“media-left”或者“media-right”來(lái)控制媒體對(duì)象中的對(duì)象浮動(dòng)方式
[注意]在 html 結(jié)構(gòu)中, .media-right 應(yīng)當(dāng)放在 .media-body 的后面
媒體對(duì)象樣式相對(duì)來(lái)說(shuō)比較簡(jiǎn)單,只是設(shè)置他們之間的間距
.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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>好的代碼像粥一樣,都是用時(shí)間熬出來(lái)的</div> </div> </div>
嵌套
在評(píng)論系統(tǒng)中,經(jīng)常會(huì)有媒體對(duì)象嵌套的需求。在Bootstrap框架中的媒體對(duì)象也具備這樣的功能,只需要將另一個(gè)媒體對(duì)象結(jié)構(gòu)放置在媒體對(duì)象的主體內(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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>好的代碼像粥一樣,都是用時(shí)間熬出來(lái)的</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"> <h4 class="media-heading">我是小火柴</h4> <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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>藍(lán)色理想衰落了,前端卻欣欣向榮起來(lái)</div> </div> </div>
對(duì)齊方式
圖片或其他媒體類(lèi)型可以頂部、中部或底部對(duì)齊。默認(rèn)頂部對(duì)齊。通過(guò).media-middle或.media-bottom來(lái)設(shè)置
.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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>藍(lán)色理想衰落了,前端卻欣欣向榮起來(lái)</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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>藍(lán)色理想衰落了,前端卻欣欣向榮起來(lái)</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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>藍(lán)色理想衰落了,前端卻欣欣向榮起來(lái)</div> </div> </div>
媒體對(duì)象列表
媒體對(duì)象的嵌套僅是媒體對(duì)象中一個(gè)簡(jiǎn)單應(yīng)用效果之一,在很多時(shí)候,我們還會(huì)碰到一個(gè)列表,每個(gè)列表項(xiàng)都和媒體對(duì)象長(zhǎng)得差不多。Bootstrap框架提供了一個(gè)列表展示的效果,在寫(xiě)結(jié)構(gòu)的時(shí)候可以使用ul,并且在ul上添加類(lèi)名“media-list”,而在li上使用“media”
媒體對(duì)象列表,在樣式上也并沒(méi)有做過(guò)多的特殊處理,只是把列表的左間距置0以及去掉了項(xiàng)目列表符號(hào)
.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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>藍(lán)色理想衰落了,前端卻欣欣向榮起來(lái)</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="http://img.jbzj.com/file_images/article/201707/huochai.jpg" alt="..."> </a> <div class="media-body"> <h4 class="media-heading">小火柴的藍(lán)色理想</h4> <div>好的代碼像粥一樣,都是用時(shí)間熬出來(lái)的</div> </div> </li> </ul>
以上這篇老生常談Bootstrap媒體對(duì)象就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
JS使用百度地圖API自動(dòng)獲取地址和經(jīng)緯度操作示例
這篇文章主要介紹了JS使用百度地圖API自動(dòng)獲取地址和經(jīng)緯度操作,結(jié)合實(shí)例形式分析了javascript與百度地圖API接口交互實(shí)現(xiàn)獲取地址與經(jīng)緯度相關(guān)操作技巧,需要的朋友可以參考下2019-04-04layui 地區(qū)三級(jí)聯(lián)動(dòng) form select 渲染的實(shí)例
今天小編就為大家分享一篇layui 地區(qū)三級(jí)聯(lián)動(dòng) form select 渲染的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09js實(shí)現(xiàn)內(nèi)置計(jì)時(shí)器
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)內(nèi)置計(jì)時(shí)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-12-12基于js與flash實(shí)現(xiàn)的網(wǎng)站flv視頻播放插件代碼
這篇文章主要介紹了基于js與flash實(shí)現(xiàn)的網(wǎng)站flv視頻播放插件代碼,該功能在很多網(wǎng)站上都有著廣泛的應(yīng)用,本文以實(shí)例形式對(duì)其進(jìn)行介紹,需要的朋友可以參考下2014-10-10element?ui?-?el-button?重新渲染后disabled屬性失效問(wèn)題解決
這篇文章主要介紹了elementui el-button重新渲染后disabled屬性失效問(wèn)題解決,解決方法也很簡(jiǎn)單,給el-button元素添加key值就可以了,需要的朋友可以參考下2023-07-07TypeScript學(xué)習(xí)筆記之類(lèi)型窄化篇
目前用TypeScript的人越來(lái)越多,尤其是一些大廠(chǎng),大的項(xiàng)目,github上面很多開(kāi)源項(xiàng)目也都是ts語(yǔ)法編譯的,這篇文章主要給大家介紹了關(guān)于TypeScript學(xué)習(xí)筆記之類(lèi)型窄化的相關(guān)資料,需要的朋友可以參考下2021-09-09