Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UL/LI list item full-width

Tags:

html

css

I have a list item that is dynamically created. Like this:

<ul class="record-top-btns">
    <li><a href="#">link1</a></li>
    <li><a href="#">link1</a></li>
    <li><a href="#">link1</a></li>
</ul>

How can create full-width ul/li with that. Like: enter image description here

Note:

  • The code should work in IE8

  • we don't know number of li item because they are dynamically created

my CSS code:

.record-top-btns{
    width:100%;
    display:table;
}

.record-top-btns a{    
    padding:2px;
    color:#5c5c5c;
    display:block;
    margin-top:2px;
    margin-bottom:2px;
    text-align:center;
    width:100%;
}

.record-top-btns li{
    display:table-cell; /* will not work in IE8 */
    background:#e3ffca;
    text-align:center;
    background:white;
}

here is a jsFiddle

like image 343
Hamed mayahian Avatar asked Dec 05 '25 10:12

Hamed mayahian


2 Answers

In IE8 you can use text-align-last:justify on the container and display:inline-block on the elements to achieve the evenly spaced effect - it just won't work in stable Chrome, so you'll need to make it a fallback with conditional comments so only older IEs use the text-align approach. For some reason IE also requires you to set text-align when setting text-align-last - keep that in mind.

Sample fiddle which works in IE/FF.

like image 177
Niels Keurentjes Avatar answered Dec 08 '25 02:12

Niels Keurentjes


going as per my comment, try jQuery, its much hassle-free

var li_count = $("ul.record-top-btns li").size();/* get number of li */
var wid = 100 / li_count; /*find li width */

$("li").css('width',wid+'%'); /* set li width */

demo

like image 30
NoobEditor Avatar answered Dec 08 '25 03:12

NoobEditor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!