問題是這樣的,使用bootstrap的柵格進(jìn)行布局的時(shí)候,如果大小超過了,會(huì)自動(dòng)的轉(zhuǎn)到下一行,但是在顯示圖片的時(shí)候就會(huì)出現(xiàn)縫隙,下面介紹masonry進(jìn)行縫隙的填補(bǔ)。
好,下面上貨。
1、首先是html
<html> <head> <title>Title</title> <meta charset="utf-8"/> <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css"/> <script type="text/javascript" src="jquery-2.1.4.min.js"></script> <script type="text/javascript" src="bootstrap/masonry-docs.min.js"></script> <script type="text/javascript" src="t.js"></script> <style type="text/css"> .container-fluid { padding: 20px; } .box { margin-bottom: 20px; float: left; width: 220px; } .box img { max-width: 100% } </style> </head> <body> <button class="btn btn-info">123</button> <div id="masonry" class="container-fluid"> <div class="box"><img src="img/p1.png">123</div> <div class="box"><img src="img/p2.png">34444444444444444444</div> <div class="box"><img src="img/p3.png">42234234</div> <div class="box"><img src="img/p4.png">234</div> <div class="box"><img src="img/p5.png">22222222222222</div> <div class="box"><img src="img/p6.png">2321213</div> </div> </body> </html> 然后是t.js
$(function() { var $container = $('#masonry'); $container.imagesLoaded(function() { $container.masonry({ itemSelector: '.box', gutter: 20, isAnimated: true, }); }); }); 最后是效果圖:

調(diào)整瀏覽器大小,讓圖片顯示成三列:

源碼下載:http://xiazai.VeVB.COm/201701/yuanma/bootstrappubu(VeVB.COm).rar
參考://m.survivalescaperooms.com/article/103444.htm
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注