1

I'm currently trying to show some categories which come from database into tables. But I want the categories to be displayed this way:

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

So my logic is to have variables to count $rows & $cols..but this won't work for every screen sizes..so I need a better approach.

The following code is just an example of the logic.

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

Is it possible to the table to detect that it has no more space and continue the <td> in next line? Here's also the jsfiddle: http://jsfiddle.net/G3fUw/

Edit: Solved, just needed to change this two lines.

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

1 Answer 1

1

By default the td has display:inline-block property so, it will never break when you reach end of DIV. so you can use display:block property for td,tr and table, or you can use DIV with float:left instead of table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.