繁体   English   中英

PHP每3个div后动态设置top属性不同

[英]php set top property different after every 3 div dynamically

我想在每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**

我想使用php动态地做到这一点。 使用for循环,我可以检查是否

$ij=0; if($ij%3==0) {
    echo "";
    }
    else {
    }

但是不确定如何获得期望的结果。

任何帮助都非常感谢。

尝试这个:

$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>";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM