Equally distribute list items in height (jQuery/CSS) -


i have responsive website grid of divs.

when open page or resize browser's width, these divs automatically resize adapt browser's width. width changing, height changing in order keep aspect ratio.

the first div embeds unordered list made of several list items (which displayed vertically in "inline-block" style).

as told before, according width of browser (when page refreshed or resized), first div automatically resize height. know how can automatically , equally change height (or line-height, or padding or margin) of these list items in order list fill vertically whole div.

it important know number of list items vary page another. given variable on page opening script should able work, whatever number of items.

this did jquery (with php variable).

var dw=$(".mydiv").width(); var dh=$(".mydiv").height(); var linum= <?php echo $how_many_li; ?>;  var verticalspace=  (dh / linum) * 100; verticalspace= math.round(verticalspace) / 100; $('.mylistblock li a').css('line-height',verticalspace+'px'); $('.mylistblock').css('width',dw); $('.mylistblock').css('height',dh); 

it kinda works messy looks ok doesn't. 70% of time it's ok , looks there moments list goes out of div's limit , moments list occupies 2/3 of it.

so, know if there more predictable/efficient/simple way achieve want (pure css perfect don't know if possible).

thank you.

i think can css only. i'm not 100% sure cross-browser compatible works in chrome (right try test other browser).

html

<div class="main-wrapper">     <ul class="mylistblock">         <li class="mydiv"><a href="#">div a</a></li>         <li class="mydiv"><a href="#">div b</a></li>         <li class="mydiv"><a href="#">div c</a></li>         <li class="mydiv"><a href="#">div d</a></li>         <li class="mydiv"><a href="#">div e</a></li>     </ul> </div> 

css

.mylistblock{     display:table;     width:100%;     height:100%;     margin:0;     padding:0; }  .mylistblock li{     display:table-row; }  .mylistblock li a{     display:table-cell;     vertical-align:middle; } 

but, .mylistblock must has defined height.

working example: http://jsfiddle.net/frogmouth/czlgs9pu/


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -