我需要在前3个div上添加不同的类。然后再重复一次课程。例如,第4个div上的第一个div类和第5个div上的2个div类,依此类推。
import java.util.Date;
import android.text.format.DateFormat;
这是我的HTML。
foreach($val as $myval)
{
?>
<div><?php $myval['name'] ?></div>
<?php
}
答案 0 :(得分:3)
试试这个:
$classes = array('class1','class2','class3'); /* Create three class */
$cnt = 0; /* Create dummy counter */
foreach($val as $myval)
{
if($cnt == 3) $cnt = 0;
?>
<div class="<?php echo $classes[$cnt];?>" ><?php $myval['name'] ?></div>
<?php
$cnt++;
}
答案 1 :(得分:1)
css nth-child()
如何为每个第三个元素设置样式?
您可以在css中添加任意样式。
.container:nth-child(1n) {
background: blue;
}
.container:nth-child(2n) {
background: red;
}
.container:nth-child(3n) {
background: lime;
}
&#13;
<div class="container first-div">
<div class="main_head col-lg-6">
<h3>Here Are Just A Testing Content</h3>
<div class="take-right">How to improve your skills.</div>
</div>
</div>
<div class="container second-div">
<div class="main_head col-sm-12">
<h3>Here Are Just A Testing Content</h3>
<h4> How to improve your skills. </h4>
</div>
</div>
<div class="container third-div">
<div class="main_head col-lg-5">
<span>Here Are Just A Testing Content</span>
<h4> How to improve your skills. </h4>
</div>
</div>
<div class="container first-div">
<div class="main_head col-lg-6">
<h3>Here Are Just A Testing Content</h3>
<h4> How to improve your skills. </h4>
</div>
</div>
<div class="container second-div">
<div class="main_head col-sm-12">
<h3>Here Are Just A Testing Content</h3>
<h4> How to improve your skills. </h4>
</div>
</div>
<div class="container third-div">
<div class="main_head col-lg-5">
<span>Here Are Just A Testing Content</span>
<h4> How to improve your skills. </h4>
</div>
</div>
&#13;