1

My code is at the end of this post.

How on earth do i get "box 3" to aligh next to "box 1" OR to the content inside "box 1" instead of aligning itself at the end of "box 2".

The important thing here is that all four boxes MUST use the same style - (style 2) as it's being used in an called by an array.

Here is what it is now and what i#m trying to make happen:

http://img524.imageshack.us/img524/1408/lastexample.gif

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {border:1px solid #000000; width:620px; position:relative;
}
.style2 {border:1px solid #000000; width:300px; float:left;}
-->
</style>
</head>

<body>
<div class="style1">

    <div class="style2">box 1<br>
      <br>
      <br>
    </div>
    <div class="style2">box 2<br>
      <br>
      <br>
      <br>
  </div>

    <div class="style2">box 3<br>
      <br>
    </div>
    <div class="style2">box 4<br>
      <br>
      <br>
    </div>
</div>
</body>
</html>
2
  • Jim, give us your PHP and someone will cook up a solution. Commented Sep 9, 2009 at 19:33
  • phh is now added to an answer on this page with instructions Commented Sep 9, 2009 at 19:56

7 Answers 7

2

Don't know of a way to get this with pure CSS using a single class for all the interior DIVs. You want something like Masonry.

Think of Masonry as the flip side of CSS floats. Where as floats arrange elements horizontally then vertically, Masonry arranges them vertically then horizontally. The result leaves no vertical gaps between elements of varying height, just like a mason fitting stones in a wall.

-The Masonry home page

Sign up to request clarification or add additional context in comments.

1 Comment

i like the look of this, but i'd rather find a simpler solution, thanks though, was interesting.
0

I think it's impossible to do that with just one style. I would probably apply float: left to every odd box and float: right to every even box. That way you can loop over your array and apply an appropriate class and not give special treatment to any particular box.

2 Comments

that sure does seem to be the correct css solution to achieve what i need. Now i need to figure out how to get allow and even and odd style in the array, which i don#'t actually know how to do :(
php, i'm not a coder, though, so to me its tricky to do things like this.
0
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {border:1px solid #000000; width:620px; position:relative;}
.style2 {border:1px solid #000000; width:300px; float:left;}

.col1 {
width:300px;
float:left;
}
.col2 {
margin-left:300px;
}
-->
</style>
</head>

<body>
<div class="style1">
<div class="col1">
    <div class="style2">box 1<br>
      <br>
      <br>
    </div>
    <div class="style2">box 3<br>
      <br>
    </div>
</div>
<div class="col2">
    <div class="style2">box 2<br>
      <br>
      <br>
      <br>
  </div>
    <div class="style2">box 4<br>
      <br>
      <br>
    </div>
</div>
</div>
</body>
</html>

2 Comments

wowza, i think you've cracked it. I'll try this on my site and report back.
spoke too soon, its an array, the code saying <div="style1"></div> is called each time for every box (using dynamic content), so i can't have new divs inbetween the calling of this.
0

I am going to assume these divs are being dynamically created.

Your current problem is you can't get the floated items any lower than the tallest of the divs in that row. I can't think offhand of a way to do what you want using css. However if you are creating these divs by looping over an array, it is solveable.

I would probably create two side by side divs and in the loop check for if the loop count is even. If it is append the dynamic div to the right column instead of the left. This will look odd, if the height of the divs ends up being greater on one side, but this could possibly be fixed by keeping track of div heights and assigning the new div to the shorter column, instead of by alternating even and odd.

1 Comment

i'd love to add an even/odd part to the loop, but at present i do not know how to do this. How's about i show you the php code for this loop, and someone could try to give me the option of an even/odd part to this?
0
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {border:1px solid #000000; width:620px; position:relative;
}
.style2 {border:1px solid #000000; width:49%; float:left;}
.style3 {border:1px solid #f00; width:49%;margin-top:-20px;float:left;}
-->
</style>
</head>

<body>
<div class="style1">

    <div class="style2">box 1<br>
      <br>
      <br>
    </div>
    <div class="style2">box 2<br>
      <br>
      <br>
      <br>
  </div>

    <div class="style3">box 3<br>
      <br>
    </div>
    <div class="style2">box 4<br>
      <br>
      <br>
    </div>
    <div style="clear:both"></div>
</div>
</body>
</html>

try this one

3 Comments

it's an array, therefore i cannot modify willy nilly inside of the loop, or can i create style 3 in the loop, its all dynamic at present.
how may iterations in ur loop? This four only ? or set of 4 divs
one div is being repeated for as many as meet the criteria, and then repeated.
0

Another one. Probably, you can mark odd and even boxes:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {border:1px solid #000000; width:620px; position:relative;}
.style2 {border:1px solid #000000; width:300px; }


.a {float:left;}
.b {float:right;}
-->
</style>
</head>

<body>
<div class="style1">
    <div class="style2 a">box 1<br>
      <br>
      <br>
    </div>
    <div class="style2 b">box 2<br>
      <br>
      <br>
      <br>
    </div>
    <div class="style2 a">box 3<br>
      <br>
    </div>
    <div class="style2 b">box 4<br>
      <br>
      <br>
    </div>
</div>
</body>
</html>

1 Comment

this will work only when the php script allows for an odd/even loop. I'm hoping someone will help me with this as i've now posted the script and where the loop is in this on this very page.
0

*FOLLOW ON TO CSS ISSUE, PHP CODE *

here is my code: http://www.pcgage.net/code.zip (sorry, pasting the code caused it to really mess up, even using the code container).

Scroll to line: 160 (to 174) - this is the loop in question. If i can simply have an odd/even, that would work perfectly. For now, who ever does this, just use the current code in the div for the new odd part, i can edit this to use a different style later.

Thanks for the help, it's been fantastic so far.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.