tags:

views:

264

answers:

2

I have a div that contains a ul and in each li there is a picture. I have floated the pictures left to get them to line up in a straight line however once it reaches the end of the div, it wraps. I would like the pictures to continue on to the right, hidden, so that I am able to create a carousel. My code is below.

The HTML

<div id="container">
    <div class="lfbtn"></div>
    <ul id="image_container">
        <li class="the_image">
            <img src="" />
        </li>
    </ul>
    <div class="rtbtn"></div>
</div>

The CSS

#container {
    width: 900px;
    height: 150px;
    margin: 10px auto;
}

#image_container {
    position: relative;
    left: 50px;
    list-style-type: none;
    width: 700px;
    height: 110px;
    overflow: hidden;

}

#image_container li {
    display: inline-block;
    padding: 7px 5px 7px 5px;
    float: left; 
}

.lfbtn {
    background-image: url(../../img/left.gif);
    background-repeat: no-repeat;
    margin: 10px;
    position: relative;
    float: left;
    top: -12px;
    left: 50px;
    height: 90px;
    width: 25px;
}

.rtbtn {
    background-image: url(../../img/right.gif);
    background-repeat: no-repeat;
    height: 90px;
    width: 25px;
    margin: 10px;
    position: relative;
    top: -101px;
    left: 795px;
}

Thanks in advance!

+3  A: 

Update your style to reflect this:

<div id="container">
    <div class="lfbtn"></div>
    <div style="width: 700px; overflow: hidden;">
        <ul id="image_container" style="width: 1000000px;">
            <li class="the_image">
                <img src="Untitled-1.gif" />
            </li>
        </ul>
    </div>
    <div class="rtbtn"></div>
    <br style="clear: both;" />
</div>

You need to set the width on a div that wraps the UL, then set overflow on that. Set your UL to have some wild width so that it will never wrap even with a lot of LI's.

To be honest I am not sure why the UL will not handle this the same as a DIV, even when the UL is set to display block. Any CSS guru care to comment.

Dustin Laine
Sorry but that does not work. simply adding the overflow: hidden; didn't have an effect on the page. I even tried removing it from the #image_container and that maintained the width and the images spilled out over the page.
Check my updated answer
Dustin Laine
Can you post your url or the images you are using. At least the dimensions of your images.
Dustin Laine
Unfortunately its on my desktop so there is no url, the thumbnails are 130x90 though..I tried to specify the width but no change....Maybe if you could post an edit to my css with the changes required.
Check my update.
Dustin Laine
Thank you very much! I really appreciate the help!
Glad it worked!
Dustin Laine
+1  A: 

Here's an working SSCCE with the minimum required styles to get it to work:

<!doctype html>
<html lang="en">
    <head>
        <title>SO question 2472979</title>
        <style>
            #images {
                width: 700px;
                height: 100px;
                overflow: hidden;
                white-space: nowrap;
            }
            #images li {
                list-style-type: none;
                display: inline;
            }
        </style>
    </head>
    <body>
        <div id="images">
            <ul>
                <li><img src="http://sstatic.net/so/img/logo.png" width="250" height="61"></li>
                <li><img src="http://sstatic.net/so/img/logo.png" width="250" height="61"></li>
                <li><img src="http://sstatic.net/so/img/logo.png" width="250" height="61"></li>
            </ul>
        </div>
    </body>
</html>

You see, the key is whitespace: nowrap;. If you want to make it a fullworthy carousel, just replace overflow: hidden; by overflow-x: scroll; and overflow-y: hidden;.

Edit: @Pool, please grow up and cut out all those serial downvotes. Thank you.

BalusC