If you know the width of the widest image (in this case 80), set the div's width to that + 20:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
div {display:inline-block; height:200px; width: 100px; overflow-x:hidden; overflow-y:auto;}
a {display:block;}
img {border:0;}
</style>
</head>
<body>
<div>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
</div>
</body>
</html>
If not (image width unknown for some reason), javascript could be used, but if the images vary in width it would have to wait until all the images are loaded. If they're all the same unknown width, the load event of the first image could be used to set the width of the div.
Example checking all images:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
div {display:inline-block; height:200px; overflow-x:hidden; overflow-y:auto;}
a {display:block;}
img {border:0;}
</style>
<script type="text/javascript">
var divWidth = {
addEvent: (function(){return window.addEventListener? function(el, ev, f){
el.addEventListener(ev, f, false);
}:window.attachEvent? function(el, ev, f){
el.attachEvent('on' + ev, function(){f.call(el);});
}:function(){return;};
})(),
init: function(){
this.addEvent(window, 'load', function(){
var pdiv = document.getElementById('pics'), ims = pdiv.getElementsByTagName('img'), imsCount = ims.length, max = 0;
while(ims[--imsCount]){
max = Math.max(max, ims[imsCount].width);
}
pdiv.style.width = max + 20 + 'px';
});
}
};
divWidth.init();
</script>
</head>
<body>
<div id="pics">
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
<a href="#"><img src="http://dl.dropbox.com/u/4017788/Labs/thumb1.jpg" alt=""></a>
</div>
</body>
</html>
Bookmarks