doudeng8691 2017-08-02 04:13
浏览 1235
已采纳

调整Bootstrap“行”以适应各种#列“col-xs-12 col-sm-4 col-md-3”?

Inserting posts on a page using WP Loop. Trying to achieve a grid layout using Bootstrap columns class "col-md-3" for example. I was able to find useful code but it's missing one part to what I'm trying to achieve. Basically, when you use the WP Loop to pull and display posts on a page you can put the Bootstrap column class "col-md-43" for each posts. That way each post is in a column and you basically create a grid of posts. Looks great, except that each row has different heights and then you have weird spacing/gaps.

OK so there are many solutions out there and I liked the one proposed by Zarko Jovic. https://stackoverflow.com/a/35963572/2243165

Basically the solution is to put the columns inside a "row" class. Problem solved.

This works except I'm not sure how to go about it if I have different columns based on the screen size. For example I use "col-xs-12 col-sm-4 col-md-3". Have no idea if it's possible to create a row that adjusts for each of the 3 different column sizes/classes. The code in the link is written to use 4 columns in a row. But when using "col-xs-12 col-sm-4 col-md-3" class the row sometimes has 1 column, sometimes 3, and other times 4 columns per row :(

Here's my code so far without placing the "row" class.

<?php
// Force loop to display defined custom post type 
$args2 = array(
    'post_type' => 'i',
    'author' => get_queried_object_id(), 'showposts' => 100
    );

$editors_pages = new WP_Query($args2);

// The loop
if ($editors_pages->have_posts()) : while ($editors_pages->have_posts()) : $editors_pages->the_post(); ?> 

<div class='col-xs-12 col-sm-4 col-md-3'>
    <div class='author-pages-title'><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4></div>
</div>

<?php endwhile; else : ?>
    <p class='align-center'>Sorry, no pages posted yet by this user.</p>
<?php endif;
wp_reset_postdata();

?>
  • 写回答

2条回答 默认 最新

  • dou7851 2017-08-02 05:09
    关注

    A good way to tackle this is to give min height to your columns. This You may need a media query for each size i.e. xs,md.

    // The loop
    
    <div class="row"> // put a div 
    if ($editors_pages->have_posts()) : while ($editors_pages->have_posts()) : $editors_pages->the_post(); ?> 
    
    <div class='special-min-height col-xs-12 col-sm-4 col-md-3'> // add a class to reference too.
        <div class='author-pages-title'><h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4></div>
    </div>
    
    <?php endwhile; else : ?>
        <p class='align-center'>Sorry, no pages posted yet by this user.</p>
    <?php endif;
    
    </div>
    

    CSS

    .row .special-min-height {
        min-height: 200px;
    }
    

    Then you can write media query for the remaining screens giving different min height.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 优质github账号直接兑换rmb,感兴趣伙伴可以私信
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)