我目前正在尝试将来自数据库的一些类别显示到表格中。但是我希望分类是这样显示的:
Animals | Other | Other --> reached end of DIV,
Restaurants | Other | Other --> the info must continue in another
Houses | Other | Other --> line
------------------------------------------------------
Other |
Other |
所以我的逻辑是让变量来计算$rows & $cols
,..but,这不会对每一个屏幕都有效,我需要一个更好的方法。
下面的代码只是逻辑的一个例子。
$categories = $all_categories();
$rows = 0;
$cols = 0;
$output = "<div><table>";
for($i = 0; $i <= count($categories) - 1; $i++){
$output .= "<tr><td>" . $categories[$i]['name'] . "</td></tr>";
}
$output .= "</table></div>";
echo $output;
表是否可以检测到它没有更多的空间,并在下一行继续执行<td>
?这也是jsfiddle:http://jsfiddle.net/G3fUw/
编辑:解决了,只需要修改这两行。
<tr style='display: inline-block'>
<td style='display: inline-block'>
发布于 2014-02-03 19:58:01
默认情况下,td
具有display:inline-block
属性,因此当您到达DIV
的末尾时,它永远不会中断。因此,您可以对td
、tr
和table
使用display:block
属性,也可以将DIV
与float:left
一起使用,而不是table
。
https://stackoverflow.com/questions/21526639
复制相似问题