【发布时间】:2013-10-10 20:01:39
【问题描述】:
如何删除作为 wordpress 循环一部分的两个 div 之间的内联块空间?它们应该并排放置,每个宽度为 50%。我意识到我可以将宽度更改为 49% 或使用浮点数,但如果可能的话,我想保持这种方式。
我知道您通常可以通过使用 cmets 消除编码中的空格来做到这一点,如下所示:
<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>
<!---->
【问题讨论】:
-
你能粘贴直接从源代码返回的内容吗?我认为开发人员工具可能会重新格式化代码留置权以便更好地阅读。
-
在 PHP 结束标记和标记之间有一个换行符(示例代码中的第 9 行和第 10 行)。你试过关闭它吗?就是这样!我非常担心循环的结束,我什至没有想到这一点。不确定我是否会将两个和两个放在一起。感谢您指出!