Reputation: 10305
I am trying to create a div where instead of the images inside moving to the next line it just keeps overflowing beyond the browser width.
HTML Markup:
<div class="carousel">
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
<img src="http://placehold.it/200x200"/>
</div>
CSS:
.carousel {
overflow: scroll;
overflow-x: hidden;
}
.carousel img{
display: inline-block;
}
Is there anyway to do this without setting a width to the div?
Upvotes: 4
Views: 753
Reputation: 983
Just to complement the other answer, if you want the carousel to scroll horizontally instead of hiding its overflow, you can hide overflow-y
and set overflow-x
to scroll:
.carousel
{
overflow-y: hidden;
overflow-x: scroll;
white-space: nowrap;
}
Upvotes: 1
Reputation: 208032
Add white-space:nowrap
to your .carousel
div:
.carousel {
overflow: scroll;
overflow-x: hidden;
white-space:nowrap;
}
http://codepen.io/anon/pen/iCqtc
Upvotes: 3