Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css - Displaying images with horizontal scroll bar

I'm trying to display a number of images horizontally inside of a fixed-width div. I would like to use a horizontal scroll bar to display the images which do not fit inside the div.

However, the images are displaying vertically, rather than horizontally. Is there a way to force them to display side-by-side?

div#event {
width: 150px;
overflow-x: scroll;
overflow-y: hidden;
}

div#event ul { list-style: none; }

div#event img {
width: 100px;
float: left;
}

<div id="lasteventimg">
<ul><li><img src="./gfx/gallery/image1.jpg" /></li>
<li><img src="./gfx/gallery/image2.jpg" /></li>
<li><img src="./gfx/gallery/image3.jpg" /></li>
</ul>
</div>  
like image 864
Dan Avatar asked Sep 09 '09 12:09

Dan


3 Answers

Correct code for arbitrary number of images, if you don't know ul width:

#lasteventimg {width:150px;overflow-x:scroll;overflow-y:hidden;}
ul {list-style:none; display:block;white-space:nowrap;}
li {width: 100px;display:inline;}


<div id="lasteventimg">
<ul>
<li><img src="./gfx/gallery/image1.jpg" /></li>
<li><img src="./gfx/gallery/image2.jpg" /></li>
<li><img src="./gfx/gallery/image3.jpg" /></li>
<li><img src="./gfx/gallery/image4.jpg" /></li>
<li><img src="./gfx/gallery/image5.jpg" /></li>
</ul>
</div>
like image 61
dneprforum Avatar answered Sep 26 '22 00:09

dneprforum


You will have to display the list items inline or float them and give the ul a very large width to avoid items moving to the next line:

ul {
  width: 10000px;    // for example
  white-space: nowrap;
}
li {
  float: left:
  // or
  display: inline;
}
like image 26
jeroen Avatar answered Sep 23 '22 00:09

jeroen


I'd go with

div#lasteventimg ul li {
  display: inline;
}

To make sure the li elements aren't rendered as block elements.

like image 31
Welbog Avatar answered Sep 24 '22 00:09

Welbog