我希望页面中的每一行都能显示3个缩略图,但它会堆叠成一行.
如何管理循环?谢谢…
foreach ($rows as $row){
?>
}
?>
此代码生成堆叠的缩略图.如何为每3列生成一行?
这个截图是我从代码中获得的:
这是我想要得到的:
解决方法:
Edit: Originally i posted this quickly from the top of my head. Thanks Wael Assaf for pointing out an improvement, which I have used. Also I have added a couple of changes to the code, now it is versatile and can be used for variable number of columns you can choose by changing the variable $numOfCols
您需要为每行添加一个div.然后你拥有的浮动div,不会只是环绕,而是将在他们自己的容器中.
bootstrap类行非常适用于此:
//Columns must be a factor of 12 (1,2,3,4,6,12)
$numOfCols = 4;
$rowCount = 0;
$bootstrapColWidth = 12 / $numOfCols;
?>
foreach ($rows as $row){
?>
$rowCount++;
if($rowCount % $numOfCols == 0) echo '
}
?>
使用php模数运算符来回显正确点处每行的打开和关闭.
希望这可以帮助.
标签:php,codeigniter,twitter-bootstrap
来源: https://codeday.me/bug/20190926/1821327.html