【问题标题】:PHP + Html tables displaying correctly infoPHP + Html 表格正确显示信息
【发布时间】:2018-07-01 06:41:19
【问题描述】:

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

    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;

表是否可以检测到它没有更多空间并在下一行继续&lt;td&gt;? 这里也是 jsfiddle:http://jsfiddle.net/G3fUw/

编辑:已解决,只需要更改这两行即可。

<tr style='display: inline-block'>
<td style='display: inline-block'>

【问题讨论】:

    标签: php html-table


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-14
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多