简体   繁体   English

如何从砌体图库中删除空白区域

[英]How to remove white space from masonry image gallery

You can check JSFIDDLE 你可以检查JSFIDDLE

在此输入图像描述

HTML HTML

<div id="container">
    <div class="item">
        <img src="http://placekitten.com/150/130" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/160/120" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/170/110" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/180/100" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/190/110" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/180/120" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/170/130" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/160/140" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/150/130" />
    </div>
</div>

JS JS

var container = document.querySelector('#container');
var msnry = new Masonry( container, {
  columnWidth: 1,
  itemSelector: '.item',
  gutter: 10
});

Just got this working while defining .item as columnWidth in masonry js. 刚刚将.item定义为砌体js中的columnWidth And adding some style to .item 并为.item添加一些样式

SEE THIS FIDDLE 看看这个好消息

JS JS

var container = document.querySelector('#container');
var msnry = new Masonry( container, {
  columnWidth: '.item',
  itemSelector: '.item'
});

CSS CSS

.item {
    width: 19.8%;
    height: auto;
    margin:0.1%;
}
.item img {
    width: 100%;
    height: auto;
}

How about trying this: (beautiful cats :p) 尝试这个怎么样:(美丽的猫:p)

<div id="container">
    <div class="item">
        <img src="http://placekitten.com/190/110" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/150/130" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/180/120" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/160/120" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/170/110" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/170/130" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/180/100" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/160/140" />
    </div>
    <div class="item">
        <img src="http://placekitten.com/150/130" />
    </div>
</div>

JSFIDDLE 的jsfiddle

That's just the nature of the plugin; 这只是插件的本质; since your code doesn't have any items small enough to fill the space, it skips past it. 由于您的代码没有足够小的项目来填充空间,因此它会跳过它。 If you can make the items smaller, even 90% of the current size, it'll be easier for the to fill the given space – think peas in a jar as compared to sand in a jar. 如果你可以把这些物品做得更小,甚至是当前尺寸的90%,那么填充给定空间会更容易 - 想想罐子里的豌豆和罐子里的沙子相比。

Beyond that, increasing gutter space might make that big gap look less intense, but not fix everything. 除此之外,增加排水沟空间可能会使这个大差距看起来不那么强烈,但不能解决所有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM