I'm trying to loop through some data passed into a Jinja2 template and populate a table.
I would like to split each <td>
cell into more sub-columns if there is more information, the number of sub-columns within the <td>
is dynamic.
Example 1
I would like each <td>
to result in something like this (i.e. no matter how many sub-columns within each <td>
, the new sub-column will be displayed in the same line):
Example 2 ##
In this example, each new sub-column within the <td>
is display below the previous one (I do not want this):
If I take this little snippet of code and open it in the browser it works as I want it to (example 1).
<html>
<head>
<style type="text/css">
.cell {
display: block;
}
.col {
float:left;
/*display: inline;*/
}
</style>
</head>
<body>
<table style="border:solid">
<thead>
<tr><th>Example 1</th>
<th>Example 2</th>
<th>Example 3</th></tr>
</thead>
<tr>
<td>
<div class="cell">
<div class='col'>
item 1 <br />
item 2 <br />
item 3 <br />
</div>
<div class='col'>
item 1 <br />
item 2 <br />
item 3 <br />
</div>
<div class='col'>
item 1 <br />
item 2 <br />
item 3 <br />
</div>
</div>
</td>
<td>
<div class="cell">
<div class='col'>
item 1 <br />
item 2 <br />
item 3 <br />
</div>
</div>
</td>
<td>
<div class="cell">
<div class='col'>
item 1 <br />
item 2 <br />
item 3 <br />
</div>
<div class='col'>
item 1 <br />
item 2 <br />
item 3 <br />
</div>
</div>
</td>
</tr>
</table>
</body>
</html>
However it does not work as expected in the template. If I use the same styling, the <td>
does not widen to accommodate the new sub-column. The <td>
does widen accommodate the text within each column.
<table>
<thead>Some information about all the cells</thead>
{% for person in list_of_people%}
<tr>
<td>
<div class="cell">
{% for item in person.activity %}
<div class='col'>
{% for element in item %}
{{ loop.index }}
{% if element['correct'] == True %}
✔
{% else %}
✗
{% endif %}
<br />
{% endfor %}
SCORE <br />= {{stats[0]}} / {{stats[2]}}
<br />
</div> <!-- col -->
{% endfor %}
</div> <!-- attempt -->
</td>
</tr>
{% endfor %}
</table>
How can I ensure that each <div>
inside each <td>
stays in the same line and doesn't get pushed below the previous one?