php set top属性在每3个div后动态变化

php set top属性在每3个div后动态变化,php,css,Php,Css,我想在每3个div之后设置不同的css TOP属性 例如: <div style="top:100px;"> </div> <div style="top:100px;"> </div> <div style="top:100px;"> </div> **Now after this the next 3 div's shall have** <div style="top:150px;"> </div&g

我想在每3个div之后设置不同的css TOP属性

例如:

<div style="top:100px;">
</div>
<div style="top:100px;">
</div>
<div style="top:100px;">
</div>
**Now after this the next 3 div's shall have**
<div style="top:150px;">
</div>
<div style="top:150px;">
</div>
<div style="top:150px;">
</div>
**Now after this the next 3 div's shall have**
<div style="top:200px;">
</div>
<div style="top:200px;">
</div>
<div style="top:200px;">
</div>
**and so on**
但不确定如何获得期望的结果

非常感谢您的帮助。

试试这个:

$top = 50;
$n = 30; // no. of divs
for($i = 0; $i < $n; $i++) {
    if($i % 3==0) $top+=50;
    echo "<div style=\"top:".$top."px;\">\n</div>";
}
$top=50;
$n=30;//分区数目
对于($i=0;$i<$n;$i++){
如果($i%3==0)$top+=50;
回音“\n”;
}
试试这个:

$top = 50;
$n = 30; // no. of divs
for($i = 0; $i < $n; $i++) {
    if($i % 3==0) $top+=50;
    echo "<div style=\"top:".$top."px;\">\n</div>";
}
$top=50;
$n=30;//分区数目
对于($i=0;$i<$n;$i++){
如果($i%3==0)$top+=50;
回音“\n”;
}

div的数量是静态的还是动态的?如果是动态的,您如何将其拉入?是否需要在每3个div之后增加
top
属性?div的数量是静态的还是动态的?如果是动态的,您如何将它们拉入?是否需要在每3个div之后增加
top
属性?