javascript - 自动高度网格

标签 javascript css grid jquery-masonry

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

我试过这样的东西 - http://patterntap.com/code/stacking-columns-layout-masonry , 但我不得不添加最小高度,但它看起来不太好,因为一些图像变小或变大了,而且包装 div 仍然是 222 像素,由于悬停效果等原因,我不希望发生这种情况。

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

最佳答案

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

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

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

添加 Masonry 插件:

给你的容器添加一个id:

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

在脚本中添加初始化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 {
    }

关于javascript - 自动高度网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17874653/

相关文章:

CSS 在 Django 管理中不起作用 : The resource from [css file url] was blocked due to MIME type (“text/html” ) mismatch (X-Content-Type-Options: nosniff

selenium-webdriver - Selenium Grid +Error forwarding the new session Empty pool of VM for setup Capabilities

twitter-bootstrap - 剑道网格页脚/寻呼机在 Bootstrap 选项卡内损坏

javascript - 读取 CSV 文件的最后一行并提取一行

javascript - 我在实现 WebRTC 时采取了正确的方法吗?

java - 在 html 中显示 sqlite 数据库查询

jquery - 动态更改基于另一个 div 高度的 div 的上边距

html - 为什么背景图像不出现在 IE8 上?

html - 流畅的网格,没有舍入误差和多个列宽

javascript - php 不显示来自 AJAX 的变量