How to adjust ul width property?
<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 may vary. What should be the width property for all images.
I tried - automatically - and expected a variable width - but it is not.
+5
5 answers
Make these changes, I think they 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>
+2
try jquery, so in the css file you can put 0 and the value will be changed 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>
0