php - (也许)停止启动 foreach 循环以修复 Bootstrap 结构
问题描述
我正在尝试使用 foreach 循环获取和显示数据,但是在使用 Bootstrap 4 获得正确的美学方面遇到了问题。
这是我想要实现的布局模型:
这是我当前的标记:
<div class="row justify-content-center">
<div class="col-12 d-flex flex-row">
<?php
$i = 0;
foreach( $col as $item ){
$itle=$item->childNodes[1]->nodeValue;
if(++$i > 4) break;
?>
<?php if ($i == 1) { ?>
<div class="large d-flex flex-column">
<span class="title"><?php echo $title; ?></span>
</div>
<?php } ?>
<!-- resourceGrid is still in the forloop, so it's rendered three times
Can I do the following here:
- stop the forloop here
<div class="resourceGrid d-flex flex-column"> so that it's only printed once
- resume the forloop
-->
<?php if ($i > 1) { ?>
<div class="resourceGrid d-flex flex-column">
<div class="small">
<span class="title"><?php echo $title; ?></span>
</div>
</div>
<?php } ?>
<?php } ?> <!-- end for each -->
</div>
</div>
但是,我所有的内容都只是连续吐出(由于flex-row
)。我认为解决这个问题的正确方法是在之前停止 for 循环,<div class="small">
但其内容将是未定义的。
我希望small
内容位于图像所描绘的列中,但不能将列嵌套在另一列中。
解决这个问题的最佳方法是什么?
解决方案
推荐阅读
- mysql - 如何在 sequelize 中将查询结果作为数组获取?
- node.js - 使用 mongoexport 时连接 sasl 对话错误(身份验证错误)
- r - 在 geom_point 图中错误地绘制反应点
- ionic-framework - 波纹效果在滚动时触发
- flutter - 如何从 dart 文件中获取 Js 文件中的设备令牌?
- html - 无法在 Angular 9 中使用 *ngFor 在选择列表中显示选项
- vba - 我需要帮助在 word 中的两个标题之间复制内容 - vba
- c# - 在 BAPI 中设置表参数失败
- vue.js - Vuelidate、v-for 和子组件化
- c++ - 如何使用另一个模板化类的实例来模板化一个类?