Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hm, I feel dirty looking at your code.<br> If your problem is that space on the right side of the container then let me explain what's going on.</p> <p>The reason that space is there is because the 6th element is too wide to stay on the same "row", and it gets pushed down to the next row. The reason it's too wide is because of the combined use of %-width and padding in your css, which never ends well. </p> <p><strong>Illustration</strong> </p> <p><img src="https://i.stack.imgur.com/dSkhX.png" alt="demonstration"></p> <p>I've constructed an example of how I think you want it to look. I also cleaned your code a little ;)</p> <hr> <h2><a href="http://jsfiddle.net/BvCqc/" rel="nofollow noreferrer">Example</a> | Code</h2> <p>In this example I use absolute values instead of percentages. The benefit from this is that I can calculate the exact width required for my container.<br> A link's width is the sum of the width + padding + margin + border:</p> <pre><code>40 + (5*2) + (2*2) + (1*2) = 56 px </code></pre> <p>And we want 5 links per "row"</p> <pre><code>56 * 5 = 280 px </code></pre> <p>So the container's width has to be at least 280px to fit 5 links per row.</p> <ul> <li>CSS</li> </ul> <pre class="lang-css prettyprint-override"><code>.hournum{ text-decoration: none; color: black; width: 40px; float: left; padding: 0px 5px; text-align: center; color: red; border-radius: 3px; border: 1px solid black; margin: 2px 2px; } .container{ position: absolute; top: 10px; left: 10px; width: 280px; background-color: white; border: 1px solid #6699FF; padding: 2px; } </code></pre> <ul> <li>Javascript</li> </ul> <pre><code>var str = ""; for(var i=1 ; i&lt;=12; i++){ var cc = i; var row if(i &lt;= 9) cc = "0" + i str += '&lt;a href="#" id="time_'+cc+'" class="hournum"&gt;'+cc+"&lt;/a&gt;"; } document.body.innerHTML = '&lt;div class="container"&gt;'+str+"&lt;/div&gt;"; </code></pre> <p><strong>Result</strong> </p> <p><img src="https://i.stack.imgur.com/QGGed.png" alt="result"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload