• Resolved nemci7v

    (@nemci7v)


    I’m making a portfolio page with 3 blocks in a row, about 4 rows down. There is a float:left and margin-right space for all the blocks. I’m using this code to remove the margin from the 3rd block in the row – so it can fit in the #container.

    <li class="folio_block <?php if($counter == 2) { echo 'folio_block_last'; $counter=0; } ; $counter++; ?>">

    On the first row, the last block has its margin removed but on the second row it does it for the 2nd block.

    I tried $counter == 3 but that picks the 4th block. I’m not sure whether it’s a code error or if I’m using floats incorrectly.

Viewing 4 replies - 1 through 4 (of 4 total)
  • you are probably setting the $counter to an initial value (outside the code you have shown here).
    if this initial value was set to 0 zero, try it with an initial value of 1 one, and use if($counter==3).

    Thread Starter nemci7v

    (@nemci7v)

    thanks, tried that too but it picks the 4th block. Weird..

    Maybe it matters on the total number of blocks I have?

    You have a problem in your code. When you set the $counter=0, it’s immediately incremented, so $counter == 2 happens one earlier than you expect.

    Try this?

    <li class="folio_block <?php if($counter == 2)
    { echo 'folio_block_last'; $counter=0; }
    else { $counter++; } ?>">
    Thread Starter nemci7v

    (@nemci7v)

    Woah! It works now! Clever code, thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Please help with $counter’ is closed to new replies.