删除两个wordpress循环元素之间的内联块空间?

时间:2013-10-10 20:01:40

标签: php html css wordpress

如何删除作为wordpress循环一部分的两个div之间的内联块空间?它们应该并排放置,每个宽度为50%。我意识到我可以将宽度改为49%或使用浮动,但如果可能的话我想这样做。

我知道你通常可以通过消除编码中的空格来做到这一点,注释如下:

<div class="before-after">
  <img src="images/ba_01.jpg" alt="">
  <h4>Frick TDSH 355XL<br><small>Slide Valve and Rotor Housing</small></h4>
</div><!-- this comment here eleminates the spacing 
--><div class="before-after">
  <img src="images/ba_02.jpg" alt="">
  <h4>Frick NGC300 Gear Plate</h4>
</div>

这是我的wordpress循环,无论我把评论放在哪里,仍然在实际返回的html中添加空格。

<?php 
  $my_query = new WP_Query(
    array( 
      'cat' => '2',             
    ) 
  );

  while ( $my_query->have_posts() ) : $my_query->the_post();
?>  
<div class="before-after">
  <?php 
    if ( has_post_thumbnail() ) { 
      the_post_thumbnail();
    } 
  ?>
  <h4><?php the_title(); ?><br><small><?php the_content(); ?></small></h4>
</div><!-- --><?php endwhile;?><?php wp_reset_postdata();?>

这就是开发者工具中出现的内容:

<div class="before-after">...</div>
<!---->
<div class="before-after">...</div>
<!---->

我确信我只是忽略了一些简单的事情,但任何帮助都会受到赞赏。谢谢!

@Prusprus这里直接源于源代码:

<div class="before-after">
    <img width="500" height="300" src="http://localhost:8888/wp-content/uploads/2013/10/ba_02.jpg" class="attachment-post-thumbnail wp-post-image" alt="Frick NGC300 Gear Plate" />
    <h4>Frick NGC300 Gear Plate<br><small></small></h4>
</div>
<!---->
<div class="before-after">
    <img width="500" height="300" src="http://localhost:8888/wp-content/uploads/2013/10/ba_01.jpg" class="attachment-post-thumbnail wp-post-image" alt="Frick TDSH 355XL" />
    <h4>Frick TDSH 355XL<br><small><p>Slide Valve and Rotor Housing</p>
    </small></h4>
</div>
<!---->

3 个答案:

答案 0 :(得分:3)

可能有不同的方式将此标记为已回答,但不确定,但@Prusprus在上面的评论中给了我解决方案。

我只需要在关闭的php标记和div的开头之间删除代码开头的换行符。

答案 1 :(得分:1)

浮动内联块元素的传统方式可以解决这个问题,但由于其不利,还有另一种方法。

您还可以将父元素的字母间距设置为-0.31em来解决此问题,并在divs中将字母间距设置为正常。我会在一秒钟内设置一个jsfiddle。

CODE

.row {
     letter-spacing:-0.31em;
}
.col {
     letter-spacing:normal;
     display:inline-block;
     width:50%;
}
祝你好运!

答案 2 :(得分:1)

这里有两种方法

  1. 将父级的font-size设置为0,然后在inline-block元素上将其恢复。

  2. 为最后一个div应用合适的保证金。

  3. DEMO x 2

    HTML

    <div class="opt1">
        <div class="before-after"></div>
        <div class="before-after"></div>
    </div>
    
    <div class="opt2">
        <div class="before-after"></div>
        <div class="before-after"></div>
    </div>
    

    CSS

    .opt1, .opt2 {    
        margin:10px;
        border:1px solid green;
    }
    
    .before-after {
        display:inline-block;
        background:lightgrey;
        width:50%;
        height:100px;
        font-size:16px
        font-size:1rem;
    }
    
    .opt1 {
         font-size:0;
    }
    
    .opt2 .before-after{
        vertical-align:top;
    }
    
    .opt2 .before-after:last-child {
        margin-left:-.25em;
    
    }
    
相关问题