tags:

views:

79

answers:

4

I'm trying to have a list of images displayed horizontaly. It's kind of like a carousel except instead of using jquery and animations I'd just have a scrollbar

<div class="playlist-wrapper">
  <ul class="playlist">
    <li> <img src='http://blah' /></li>
    <li> <img src='http://blah' /></li>
    <li> <img src='http://blah' /></li>
    <li> <img src='http://blah' /></li>
  </ul>
</div>

.playlist-wrapper{width: 500px; overflow-x:scroll}
ul{width: 10000px;}
li{float:left}

The problem here is that I have to define the width of the UL tag because if I don't the images are going to go the next line and I'm going to get an Y scroll that I don't want.

I can't use jQuery. I tried no-wrap, but this only works for text.

Any idea?

+2  A: 

Defining the width is the only option to prevent the li elements from wrapping. Trust me, I've used a lot of hours with the same problem and I'd be surprised if anyone can come up with anything better :)

If you can't use JavaScript, perhaps you can calculate the width on the server side?

Tatu Ulmanen
What if I didn't use the whole ul/li structure and use something else, do you think there'd be a way around ?
marcgg
Not to my knowledge, I'm afraid. I hope someone will prove me wrong on this subject, though.
Tatu Ulmanen
I can calculate the width on the server side, but I was hoping for a more elegant solution ^^
marcgg
@tatu actually @boldewyn found a solution !
marcgg
+3  A: 
ul {
  white-space: nowrap;
}

li {
  display: inline;
  /* or, for 'blockness': */
  display: inline-block;
}

Works in my FF3.6, but haven't tried it elsewhere. Also, the content of the ul must all be inline elements (or made to such).

Boldewyn
after testing actually I needed to remove the float (forgot to do so). This seems to be working !
marcgg
That's my test file: http://jsbin.com/ikove . If you have the `float:left` still in your stylesheet, you have to remove it.
Boldewyn
By the way: This solution doesn't work, if you don't set an explicit value for the width of the ul. *That* is something I still get headaches from thinking about.
Boldewyn
@boldewyn: what do you mean? "This solution doesn't work, if you don't set an explicit value for the width of the ul."
marcgg
My mistake. Forget the last comment, sorry.
Boldewyn
A: 

Try not to use the ul/li structure at all and just place images one after the other, that should work.

Guillaume Flandre
Thx for the solution. This works, but I need the wrappers so this isn't good for me
marcgg
+1  A: 

Just replace

li {float:left}

with

li {display:inline}
Robusto