views:

2215

answers:

5

Hi,

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>
+1  A: 

I'd go with

div#lasteventimg ul li {
  display: inline;
}

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

Welbog
A: 

Well first of all, you need to change your styles from #event to #lasteventimg. Then, if you set the width of the ul to be wide enough to accommodate all the images, you should see the behavior that you're trying to get:

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

div#lasteventimg ul { list-style: none; width: 300px; }

div#lasteventimg 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>
Donut
+1  A: 

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;
}
jeroen
A: 

You need to change your list, so the elements are rendered horizontally rather then the default vertical.

#imagelist li
{
display: inline;
list-style-type: none;
}
Dominic Bou-Samra
A: 

Why don't you try this?

ul { width: 10000px; white-space: nowrap; }

li { display: block; float:left; }

Ramesh