Reputation: 6436
I want to break to a new line after each 6th record but it only breaks after 5th record and leaving the 6th record on a own line (see picture below).
for($i = 1; $i < 13; $i++) {
echo '<div style="display: '.($i % 6 == 0 ? '' : 'inline-').'block; padding: 0 10px;"></div>';
}
What am I doing wrong here? How can I fix it?
Upvotes: 0
Views: 171
Reputation: 20469
As per my comment, your logic is flawed as a block element will have 100% width.
Instead reduce the width of the container and leave all elements as inline-block:
<div id="infopage-prognosis" style="display: block; width:450px">
<?php for($i = 1; $i < 13; $i++) {
echo '<div style="display: inline-block; padding: 0 10px;"></div>';
} ?>
</div>
Upvotes: 0
Reputation: 3005
set all the items with display:inline-block
and after the 6th element add:
<div style="clear:both"></div>
tested it on your website and it worked
Upvotes: 1
Reputation:
It is normal you get that result, it is rather a mathematical logic:
for($i = 1; $i < 13; $i++) {
echo '<div style="display: '.($i % 7 == 0 ? '' : 'inline-').'block; padding: 0 10px;"></div>'; ^
}
Upvotes: 0
Reputation: 331
The width of six clouds (with spacing) is probably more than the available space in the cloud container. Check for whitespaces or increase outer container width (or reduce padding)
Upvotes: 1
Reputation: 28753
You can try with 7
echo '<div style="display: '.(($i % 7 == 0) ? '' : 'inline-').'block; padding: 0 10px;"></div>';
Upvotes: 1