douliao8402 2016-08-23 13:31
浏览 21

无法在一行帖子中添加margin-right

Right now I have 3 posts in a row, 3 posts in the next row, and 1 post in the next row, and so on. I am trying to add space in-between the posts that have 3 in a row. Every time I add css margin-right:25px; to .col-mod-4 { it adds the space but 1 post gets knocked off the row, and instead I have 3 rows of 2 posts. Does anyone have any solutions? (I have attached a dropbox link with screenshots of the problem)

https://www.dropbox.com/sh/fbi17l2ortzpqkk/AACDm2XIcvJDjouAb0zPilfVa?dl=0

Here is my index.php

<?php
/*
 * Template Name: learningwordpress
 */
 
get_header();
 
$i = 0;
 
$args = array(
    'posts_per_page' => 14,
    'paged' => 1
);
 
$the_query = new WP_Query($args);
 
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
 
        if( $i %2 == 1 ) {
                   $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>      
            <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
 <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>

 <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>      
            <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
 <?php $the_query->the_post(); ?>
            <article class="post col-md-4">
                <?php the_post_thumbnail('medium-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
            <?php

        }
        else {
         $the_query->the_post(); ?>
            <article class="post col-md-12">
                <?php the_post_thumbnail('large-thumbnail'); ?>
                <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                <p>
                    <?php echo get_the_excerpt(); ?>
                    <a class="moretext" href="<?php the_permalink(); ?>">Read more</a>
                </p>
            </article>
            <?php
        }
        ?>
        <?php
        $i++;
    }
}
else {
    echo '<p>Sorry, no posts matched your criteria.</p>';
}
get_footer();

</div>
  • 写回答

1条回答 默认 最新

  • doushenxu7294 2016-08-23 14:52
    关注

    Try padding-right instead of margin-right

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教