简体   繁体   English

Wordpress博客循环,自动高度中断布局

[英]Wordpress blog loop, automatic height breaks the layout

Ok guys, I have a blog post loop in which the limit is 6 per page, they are side-by-side with a 'col-md-6' getting like this, two per line. 好的,我有一个博客帖子循环,其中每页限制为6个,它们并排排列着“ col-md-6”,每行两个。 However, some posts have the title on one line and others on two lines, thus making one bigger than the other, and when that happens the layout gets broken, as you can see in the image 但是,有些帖子的标题仅占一行,而另一些则占两行,因此使一个标题比另一行大,并且发生这种情况时,布局就被打乱了,如您在图像中所见

在此处输入图片说明

Code of box 箱号

<div class="col-md-6 col-sm-12 blog-padding-right">
                            <div class="single-blog two-column">
                                <div class="post-thumb">
                                    <a href="<?php the_permalink(); ?>"><div class="div-bg-capa" style="background:url(<?php the_post_thumbnail_url( 'large' ); ?>);width: 100%;height: 200px;margin: 12px 0;background-size: cover;background-position: center;"></div></a>
                                </div>
                                <div class="post-content overflow">
                                    <h2 class="post-title bold"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                    <p>
                                    <?php echo excerpt('20'); ?>
                                    </p>
                                    <a href="<?php the_permalink(); ?>" class="read-more">Ver mais</a>
                                </div>
                            </div>
                        </div>

Is there some trick in css or using the bootstrap itself so it stays that way? CSS或使用引导程序本身是否有一些技巧,使其保持这种状态?

在此处输入图片说明

We can not see your css, but if you are using floats for post (which you most likely are), you can add clear: both to odd posts. 我们看不到您的CSS,但是如果您在帖子中使用浮动元素(很可能是这样),则可以添加clear: both都添加到奇数帖子中。 It has better browser support than flex-wrap: wrap 它比flex-wrap: wrap具有更好的浏览器支持flex-wrap: wrap

 .post{ background-color: #aaa; width: 50%; float: left; outline: 1px solid black; } .post:nth-child(odd){ background-color: #ddd; clear: both; } 
 <div class="posts"> <div class="post">Lorem ipsum<br>dolor sit</div> <div class="post">Lorem ipsum</div> <div class="post">Lorem ipsum</div> <div class="post">Lorem ipsum<br>dolor sit</div> <div class="post">Lorem ipsum</div> <div class="post">Lorem ipsum</div> </div> 

An easy way to address this is to use display: flex; flex-wrap: wrap; 解决此问题的一种简单方法是使用display: flex; flex-wrap: wrap; display: flex; flex-wrap: wrap; on the posts container, then width: 50%; 在邮政集装箱上,然后width: 50%; on the posts. 在帖子上。

 .posts { display: flex; flex-wrap: wrap; width: 960px; margin: auto; } .post { background: #eee; width: 50%; } .post:nth-child(3) { height: 100px; background: #aaa; } .post:nth-child(5) { background: #ccc; height: 250px; } .post:nth-child(6) { background: #ccc; height: 125px; } 
 <div class="posts"> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> <div class="post">asdf</div> </div> 

You can also use plugins that address this kind of layout. 您也可以使用可解决这种布局的插件。 One I really like is Masonry - http://masonry.desandro.com/ 我最喜欢的一个是砌体-http: //masonry.desandro.com/

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

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