I am looking to create a viewer consisting of an arbitrary number of horizontally aligned divs, where only 3 are visible at any given time.
<div id="viewport"> <div id="slides"> <div>Content 1</div> <div>Content 2</div> <div>Content 3</div> <div>Content 4</div> <div>Content 5</div> <div>...</div> </div> </div>
My approach is to have a parent div ("viewport") with a fixed width / height and overflow: then hide its child div ("slides"), which has the actual content in its child divs, left or right.
For this to work, I need the child divs of the βslidesβ to be horizontally aligned, not one of them wrapped below, which will happen by default. I succeed when I know and specify the cumulative width of the children of the "slides" div in CSS, but I will dynamically add / remove them in JS. I would like to avoid having to constantly change the width of the βslidesβ of the div through JS, and rather just learn how to do this in CSS.
In short, how can I prevent a series of divs from wrapping below if the total width is unknown?
source share