【问题标题】:Masonry has spaces yet all cells have same width砌体有空间,但所有单元格的宽度相同
【发布时间】:2017-07-03 16:22:43
【问题描述】:

很奇怪,砌体缺少大空间,但所有li 的宽度都相同:

HTML:

<div class="one-gallery">
    <section class="grid-wrap">
        <ul class="one-grid">
            <li class="grid-sizer"></li><!-- for Masonry column width -->
            <li class="itemMG">
                <figure>
                    <img alt="Img 0 " src="images/1.jpg" >
                    <figcaption><h3> 0 Letterpress asymmetrical</h3><p>Chillwave hoodie ea gentrify aute sriracha consequat.</p></figcaption>
                </figure>
            </li>
            <li class="itemMG">
                <figure>
                    <img alt="Img 0 " src="images/2.jpg" >
                    <figcaption><h3> 1 Letterpress asymmetrical</h3><p>Chillwave hoodie ea gentrify aute sriracha consequat.</p></figcaption>
                </figure>
            </li>
        </ul>
    </section>
</div>

CSS:

.one-gallery ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.one-gallery figure {
    margin: 0;
}

.one-gallery figure img {
    display: block;
    width: 100%;
}
/* Grid style */
.grid-wrap {
    max-width: 1400px;
    margin: 0 auto;
}

.one-grid {
    margin: 0 auto;
}

.one-grid li {
    width: 24%;
    float: left;
    cursor: pointer;
}

.one-grid figure {
    padding: 15px;
    -webkit-transition: opacity 0.2s;
    transition: opacity 0.2s;
}

JS: 砌体自动启动。 * 砌体包装 v4.2.0

它们都具有相同的宽度,因此不应有任何空白。我能做些什么来解决它?

【问题讨论】:

    标签: jquery css jquery-masonry


    【解决方案1】:

    我认为你不使用 imagesLoaded https://imagesloaded.desandro.com/ 。因此,您的砌体布局是在加载所有图像之前创建的 - 这就是您有这些差距的原因。

    function isotope_layout(){
    
        var $container_main_page = jQuery('.masonry_container');
    
        // MAIN CONTAINER
    
        $container_main_page.isotope({
    
            itemSelector: '.post_masonry',
            masonry: {
                layoutMode: 'fitColumns',
                gutter: 0
            },
    
        });
    
        $container_main_page.imagesLoaded( function() {
    
            $container_main_page.isotope('layout');
    
        });
    }
    

    【讨论】:

    • 我很抱歉,实际上砌体并没有被激活,这个行为是float:left on .one-grid li 。我只需要添加:$(".one-grid").masonry({ itemSelector: ".itemMG" });。感谢您的帮助,它让我找到了它。 :)
    • 好,很高兴能帮上忙;)ps。 float:left 不要破坏布局,因为砌体将为每个项目设置 position:absolute ...但是是的,您需要设置 itemSelector :)
    猜你喜欢
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 2013-06-08
    • 2014-02-26
    相关资源
    最近更新 更多