Szymon Dziewoński Szymon Dziewoński - 3 months ago 6
CSS Question

count width for 4x verse container

I would like to create easy script for counting width and sum for width of container.
Here's example:
http://codepen.io/Szymon_Dziewonski/pen/ycJxf

I need to specify width of

#inner
if i want 4 line on this specific
#container
width.
If not
ul li
just go in one line.
As you can see my count isnt good enough for this problem when there is no exact amount of
li
.
For example

10
li
= (40 * 100px) /4 = 1000px so it is good anwser #inner will be 1000px and will be 4 lines (10 + 10 + 10 + 10)
li's


but if:

15
li
= (25 * 100px) /4 = 625px so it is #inner 625 4 lines * 6
li's
+ 1
li's


Problem is when number of
li
is odd or even = result is different

If anyone has idea how to solve this problem I would be most pleased and help will be appreciate!
Thank you.

Answer
var accum_width = 0;
var test = Math.ceil($('#inner li').size()/4)*102;

if(test > 1122){
  $('#container').width(test);
}else{
    $('#container').width(1122);
}    

thats the anwser 'math.ceil'