views:

65

answers:

2

My code is something like the below. When theres 3 images everything is fine once theres 4 it gets full and moves the entire div.top into another row. How do i make the div inside top just start a new row instead?

I tried writing .top width=500px but once it hits or passes it instead the images inside are squeeze together instead of each being 150x150. I tried max-width on top instead and in opera and chrome i see the border of top as 500width but the images continue to render pass it. (i have a firefox problem with my div so the width looks fixed to something else).

So how do i make these divs go into another row? and not try to squeeze together

<div class="top">
<div><a href><img/></a></div>
<div><a href><img/></a></div>
<div><a href><img/></a></div>
</div>
+3  A: 

I may need more information here, it's hard tell exactly what's happening. A screen-shot perhaps?

I would probably start with something like this:

.top {
  width: 500px;
  overflow: hidden;
}

.top div {
  display: inline;
  float: left;
  width: 150px;
  height: 150px;
}
Eric Meyer
+1  A: 

Here's a solution that might help (used it in my example, just customized to fit your example)

.top {
  display: block;
  padding: 0;
  margin: 0;
  width: 100%;
}

.top div {
    float: left;
    display: block;
    margin-right: 5px;
    margin-bottom: 10px;
    width: 47%;    /* Not needed, but in my case I needed 2 columns */      
}

Basicall, the .top div float: left; is what is making my images to go to next row if columns are full.

The Elite Gentleman
The first `display: block;` is redundant on a div, and the second will cause an IE bug - that should be replaced by `display: inline;` for best practice (with no effect on other browsers). Also: the mix of % width and px margins is also dangerous - I would choose one or the other.
Eric Meyer
@Eric Meyer, combining `display: inline;` and `float: left;` doesn't gel well when used in IE. It's either you use 1 or the other. I've had issues with all versions of IE when adding the 2 together. And the margin are not necessary at all. I just took my working CSS, added width on top of it (for the div it was 300px in my case).
The Elite Gentleman
I don't know what you are talking about. `display: inline;` on floats is best practice, fixing the bug described here: http://www.positioniseverything.net/explorer/doubled-margin.html - and has absolutely no side-effects.
Eric Meyer