0

I've got a list item with an image inside, for example:

<ul>
    <li>
        <img></img>
    </li>
</ul>

The image does not take up the full width of the li.

How can I get the li width to shrink to the size of its containing image?

2
  • The ul has a set width...if this has anything to do with it...?? Commented Jun 26, 2012 at 6:09
  • 2
    show your code in jsfiddle.net for better understanding. Commented Jun 26, 2012 at 6:14

4 Answers 4

1

Do the height of images

   <ul>
        <li>
            <img src="" width="xxx" height="xxx"></img>
        </li>
    </ul>

Live demo http://jsfiddle.net/CZqEc/

updated live demo http://jsfiddle.net/CZqEc/1/

Sign up to request clarification or add additional context in comments.

1 Comment

Is it possible to get the li to shrink dynamically though?
0

If you set your li to display: inline, since li are blocks by default, the width would match the largest/widest element.

Comments

0

If <li> is display:block or similar (list-item also)

use li img{max-width:100%}


If <li> is display:inline-block or display:inline you also need to set <li> width

Comments

0

or try

li
{
background:url('');
display:   ;
background-size:xx xx;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.