9
<ul id='ul01'>
    <li><a href='#'><img src='img01.png' width="700" height="590" /></a></li>
    <li><a href='#'><img src='img02.png' width="700" height="590" /></a></li>
    <li><a href='#'><img src='img03.png' width="700" height="590" /></a></li>
</ul>

CSS:

#ul01{list-style:none;width:??;}
#ul01 li{float:left;}

This is a horizontal array of images. list.items.count can vary.
What should be the width property to fit all images.
I tried with - auto - and expected resizible width - but it's not.

Alice
  • 613
  • 4
  • 12
  • 24

5 Answers5

13

Make the li elements inline-blocks and set the white-space property of the ul to nowrap.

li {
    display: inline-block;
}
ul {
    white-space: nowrap;
}
magicalex
  • 917
  • 7
  • 11
2

Make these change i think these will work for you...

#ul01{list-style:none;width:100%;}
#ul01 li{float:left; width:33%; }
#ul01 li a { display:block; }
#ul01 li a img { width:100%; height:auto; }

<ul id='ul01'>
    <li><a href='#'><img src='img01.png' /></a></li>
    <li><a href='#'><img src='img02.png' /></a></li>
    <li><a href='#'><img src='img03.png' /></a></li>
</ul>
thirtydot
  • 224,678
  • 48
  • 389
  • 349
SaurabhLP
  • 3,619
  • 9
  • 40
  • 70
1

if your images have to retain the sizes you specified then know that your page will have horizontal scrollbar. If you prefer that this will work

#ul01{list-style:none;width:2100px;}
#ul01 li{float:left; width:700px}

The ul width has to be the (width X 3) + (2 X image-border-if-any} + padding = 2100px + n

codingbiz
  • 26,179
  • 8
  • 59
  • 96
0

try jquery, so in css file you can put 0, and value would be change later.

<script type="text/javascript">
  $(document).ready(function () {
    var sum = 0;
    $('#ul01 li img').each(function() {
      sum += parseInt($(this).attr("width"), 10);
    });
    $('#ul01').css({ 'width': sum+'px' });
  });
</script>
miszczu
  • 1,179
  • 4
  • 19
  • 39
0

You just put width property to ul element.

Meigo62
  • 163
  • 1
  • 2
  • 12