tags:

views:

58

answers:

3

Hi everyone,

I am working on a photo gallery, each thumbnail is in its own DIV and floated to the left in a containing DIV. It has been displaying properly up until vertical thumbnails entered the equation. Now, when the next row should start, the first item of the following row is to the left of the last vertical DIV (thumbnail), rather than flush to the left of the containing DIV.

alt text

Here is the CSS:

#galleryBox {
        width: 650px;
        background: #fff;
        margin: auto;
        padding: 10px;
        text-align: center;
        overflow: auto;
    }
    .item {
        display: block;
        margin: 10px;
        padding: 20px 5px 5px 5px;
        float: left;
        background: url('/images/content_bottom.png') repeat-x scroll bottom #828282;
        }

and the HTML:

<div id="galleryBox" class="ui-corner-all">
                <div id="file" class="ui-corner-all">
                    <form name="uploadPhoto" id="uploadPhoto" method="post" action="" enctype="multipart/form-data">
                        <p><label for="photo">Photo:</label><input type="file" name="photo" id="photo"/></p>
                        <p><label for="caption">Caption: <small>Optional</small></label><input type="text" id="caption" name="caption"/></p>
                        <p align="center"><input type="submit" value="Upload" name="send" id="send" class="addButton ui-state-default ui-corner-all"/></p>
                    </form>
                    <a name="thumbs"></a>
                </div>
                <div class="item ui-corner-all">

                    <a href="http://tapp-essexvfd.org/gallery/photos/201004211802.jpg" class="lightbox" title="test1">
                        <img src="http://tapp-essexvfd.org/gallery/photos/thumbs/201004211802_thumb.jpg" alt="test1"/></a><br/>
                    <p><span class="label">test1</span></p>
                </div>

                <div class="item ui-corner-all">
                    <a href="http://tapp-essexvfd.org/gallery/photos/201004211803.jpg" class="lightbox" title="test3">
                        <img src="http://tapp-essexvfd.org/gallery/photos/thumbs/201004211803_thumb.jpg" alt="test3"/></a><br/>
                    <p><span class="label">test3</span></p>
                </div>
</div>
+1  A: 

Two options:

  1. Set a maximum height for the thumbnail DIVs, so that they layout correctly, regardless of whether they are horizontal or vertical.
  2. Use "clear: left" to reset the float on the thumbnail DIV next to the vertical.

The default behavior appears correct, based on what happens when text flows around a floated DIV. Based on what you're trying to do, I would choose option #1.

Neil T.
+1  A: 

you could try using css table displays for your divs... ie.

#galleryBox {
    display: table;
    ...
}
.item {
    display: table-cell;
    ...
}
.row {
    display: table-row;
}

so you'd have to add another div to wrap around the items in each row

<div id="galleryBox">
    <div class="row">
        <div class="item">image</div>
        <div class="item">image</div>
        <div class="item">image</div>
        <div class="item">image</div>
    </div>
    <div class="row">
        <div class="item">image</div>
        <div class="item">image</div>
        <div class="item">image</div>
        <div class="item">image</div>
    </div>
</div>
quagland
The problem with tables, and with wrapping the divs in their row, is that you lose a lot of flexibility. With floating divs, you do not need to calculate how many divs will fit in each row. With the method you suggest, this must be pre-defined.
Daniel Vassallo
This is interesting and I was actually wondering if something like this was possible, but unfortunately won't work for my situation as the content is from a database (variable). But thanks for the tip! :)
NightMICU
+1  A: 

You can use Inline-Blocks as described in this article:

The article solves the same exact problem you are having with thumbnails.

I also found this simple example using inline-block thumbnails. Note how the thumbnails wrap nicely and remain vertically aligned within their line.


UPDATE:

Here is another detailed article that tackles this problem with the inline-block:

As you can notice from these articles, it is a bit tricky to make it work cross-browser.

Daniel Vassallo
Thank you so much! The Cross-Browser Inline-Block tutorial worked like a charm, looking snazzy now! :)
NightMICU