简体   繁体   English

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

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

I want to set the css TOP property different after every 3 div's 我想在每3个div之后设置css TOP属性不同

for eg: 例如:

<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**

I want to do this dynamically using php. 我想使用php动态地做到这一点。 Using the for loop i can check if 使用for循环,我可以检查是否

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

But not sure how to get desired result. 但是不确定如何获得期望的结果。

Any help is really appreciated. 任何帮助都非常感谢。

Try this: 尝试这个:

$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