简体   繁体   中英

Adding css classes to html element dynamically in php

I am trying to build an application which has many courses.Each course has some days(eg 14 days or for another course 20 days).And to keep track on this I have a step progress bar.Which look like this: 在此处输入图片说明

Now in this example 14 days which are big circles with a lock icon.small circles in between are test quiz.

I am using laravel for this. I am fetching all this data from the database and producing this step progress bar like this:

     <ul class="progressbar">
        @for($i=1;$i< $totalDays->total_days*2;$i++)
          <li class=""></li>
        @endfor    
     </ul>

Now I want to add the active class to the active day (on which day currently is).

Like This:

<li class="active"></li>

How can I achieve this in PHP?

Thank you.

You could try to do this:

<li class="<?php if ($i/2 == $current_day-0.5) { echo "active"; } ?>"></li>

It checks if the day number ( $current_day ) equals to the number of the circle ( $i ), if yes, it adds the class active to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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