Hi guys,

I love the layout of this site (http://spacecollective.org/gallery/). The image can reflow when browser size change but still keeps vertical distance between them. I want to use it for my image collection. But don't know how to make it work. I have try to do with css but my layout became chaos. Can anyone here help me... Thank you very much.

Comments

Jeff Burnz’s picture

The layout technique the site is using is quite tricky, I wonder if they're using JavaScript to write the classes for each div...

I would think you can achive a very similar thing by using a simple float left declaration.

.myclass img {
float: left;
margin: 0 10px 10px 0;
}

Where myclass is set on the parent containing div.

Things start getting a bit ugly when images are different widths (if you want to preserve a nice grid-like layout that is), in which case you need to set width on the div surrounding the actual image (just like the site you refer to does). You can also set a min-height, or a hard height value if you're really wanting a real grid.

Lets say you have output that looks like this (lets think there are many of these output in the gallery page):

<div class="field-image">
  <img src="myimage.jpg" />
</div>

Then your CSS starts looking something like this;

.field-image {
float: left;
width: 220px;
min-height: 220px;
margin: 0 10px 10px 0;
}

This will reflow as the width of the page changes, as it gets narrower the right-most images will be pushed down to the next row and so on.

In any case, it'll take a bit of mucking around to get what you want, although the idea is pretty simple.

Need help with IE?
Learn basic XHTML and CSS first.
Get smart with web specs.

nikenhn’s picture

I tried to do as you said. But it not quite exactly what I want. I want to layout images with difference height. So lets think that I have 3 images (same width) numbered from (1) to (3). I laying out 3 images in a row (3 columns). (1) & (3) are 100px height images, (2) is 500px height. When I narrow the browser width, my layout now have 2 images in a row and (3) pushed down to 2nd row. The gap between 1 & 3 is too big because of the height of (2) image. I want to have (3) right below (1) image. If you know there's a solutions somewhere. Please point me there. Thank you very much.

neurer’s picture

nikenhn’s picture

Wow, Thats great Jant. I still don't know how to use that js file. But thank you very much