0

我的电子商店(http://shop.rukahore.sk/)上有一个产品网格。每个产品 div 都是 222px x 222px,但我希望它具有自动高度。

我试过这样的东西 - http://patterntap.com/code/stacking-columns-layout-masonry,但我不得不添加 min-height 并且它看起来不太好,因为一些图像更小或更大并且包裹div 仍然是 222px,由于悬停效果等,我不想发生这种情况。

有人可以就此提供建议吗?

4

1 回答 1

0

好吧,要使用该页面中显示的显示,您需要使用插件

<!-- Requires Masonry | visit http://masonry.desandro.com/ to download -->

如果您不想添加更多插件...好吧,让您失去高度的是 float css 属性。您应该使用其他东西来制作网格,例如在 www.camarasdecolores.com 中查看他们是如何做到的。

添加砌体插件:

为您的容器添加一个 id:

<div id="masonryContainer" class="hp-products allposts" style="position: relative; height: 2008px;">

在脚本中添加init js代码

$(window).load(function(){
  $('#masonryContainer').masonry({  
    itemSelector: '.hp-product',
    columnWidth: 60
  });  
}); 

改变一些CSS:

#masonryContainer { width: 0 auto; }

.hp-product {
    width: 180px; float: left;  
}
.hp-product-img {

}
.hp-product-img img {
    max-width: 100%;
    height: auto;
    }
//Void the following ones
    .hp-products {
    }
    .allposts {
    }
    .allposts .hp-product {
    }
于 2013-07-26T07:24:07.223 回答