<?php foreach ($rows as $id => $row): ?>
<li class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
<?php endforeach; ?>
以上代码用于输出文章列表。现在我想在 10 的倍数的行之后添加大空间。即,在每10 个要点。如何更改上面的代码。然后我可以使用 css 来获取它。 –
最佳答案
虽然我不知道你所说的“大空间”是什么意思,我假设你想在每第 10 个列表项之后放置一个任意的 HTML 标记。您可以这样做,例如:
<?php $i = 0; ?>
<?php foreach ($rows as $id => $row): ?>
<li class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
<?php if ($i++ === 10): ?><br /><?php $i = 0; endif; ?>
<?php endforeach; ?>
编辑,你澄清了:
no,eg:30px, but the space between other
<li>
is 20px.
可以这样做:
<?php $i = 1; ?>
<?php foreach ($rows as $id => $row): ?>
<?php $i++; ?>
<li style="margin-bottom:<?php echo ($i === 10) ? : '30' : '20'); ?>px;" class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
<?php if ($i === 10) $i = 1; ?>
<?php endforeach; ?>
关于php - 如何增加大空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4967110/