user681061
user681061

Reputation: 255

Dynamic image width in ul/li

I have code that sets li width dynamically on window resize. It divides 100% with the current number of li tags.

Code looks like this:

$(document).ready(function() {
    var num = $('li').length;
    var width_li = 100 / num;
    $('li').css('width', width_li + '%');
});​

Test it here: http://jsfiddle.net/jbew7/

How can I make it resize images that's inside the li tags to?

Upvotes: 1

Views: 607

Answers (2)

Talha Akbar
Talha Akbar

Reputation: 10030

li img {
   width: 100%;
   height: 100%;
}

100% percent will make sure that image width/height remains same as the width/height of li..

Upvotes: 0

Ram
Ram

Reputation: 144669

You can use CSS:

li img {
   width: 100%;
   height: auto;
}

Upvotes: 3

Related Questions