views:

71

answers:

1

I would like to have several items stack horizontally infinitely (in one row), without setting the width of their parent container. I'm fully aware that setting the container div to width:1000px; will make them stack, but for various reasons I do not want to use this solution. Are there any alternatives?

<html>
<head>
<style type="text/css">
div {white-space:nowrap; clear:none;}
div div {width:300px; border:1px solid black; float:left; display:inline;}
</style>
</head>
<body>
<div>
    <div>x</div>
    <div>x</div>
    <div>x</div>
    <div>x</div>
    <div>x</div>
    <div>x</div>
</div>
</body>
</html>
A: 

It's not necessarily a robust solution, but if you can get exactly 300px of content in each of the inner divs, you could remove the float and width properties. Maybe include a 1x300 transparent image, and make sure you don't have too much text? Maybe

div.dummycontent {float:left; width:200px; background-color:Blue; }
<div class="dummycontent">&nbsp;</div>

Or if the reasons for not setting a width are primarily along the lines of not knowing until runtime what the size will need to be, maybe calculate with JavaScript, and set it then?

joelt