I was wondering if there is still no good way to stretch a div and scroll horizontally according to the images inside. In the end, now is 2011!
mega-width performs the trick, but leaves mega-space empty if it is not filled with images.
If there is too much filling, images are not displayed. The same goes for jQuery. The situation below is the best I can do after hours of working at Google, but it is not reliable enough.
Thank you for your time.
* { margin:0; padding:0; } #one { width: 200px; height: 250px; overflow-x: auto; overflow-y: hidden; } #two { width: 10000em; } #two img { float: left; } $(document).ready(function() { var total = 0; $(".calc").each(function() { total += $(this).outerWidth(true); }); $("#two").css('width', total); alert(total); });
<div id="one"> <div id="two"> <img src="images/testimage3.jpg" width="480" height="192" class="calc"> <img src="images/testimage3.jpg" width="480" height="192" class="calc"> <img src="images/testimage3.jpg" width="480" height="192" class="calc"> <img src="images/testimage3.jpg" width="480" height="192" class="calc"> </div> </div>
jquery css image overflow scrollbar
ams
source share