PHP + Html表显示正确的信息

时间:2014-02-03 11:49:55

标签: php html-table

我目前正在尝试显示一些来自数据库的表格。但我希望以这种方式显示类别:

    Animals        |   Other    |   Other    --> reached end of DIV, 
    Restaurants    |   Other    |   Other    --> the info must continue in another
    Houses         |   Other    |   Other    --> line
------------------------------------------------------
    Other          |
    Other          |

所以我的逻辑是让变量计算$rows & $cols ..但这对每个屏幕尺寸都不起作用。所以我需要一个更好的方法。

以下代码只是逻辑的一个例子。

$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'>

1 个答案:

答案 0 :(得分:1)

默认情况下,td具有display:inline-block属性,因此当您到达DIV时,它永远不会中断。因此,您可以对display:blocktdtr使用table属性,也可以将DIVfloat:left一起使用,而不是table }。