2017-03-16 1 views
0

Hier ist der Code für die Benachrichtigung Code:Wie kann ich die Hintergrundfarbe von div ändern, wenn die Bedingung erfüllt ist?

<?php if(isset($notification) && $notification->result() >0){?> 
    <div class="panel-heading pull-right col-md-6" 
    style="height:140px; margin-top:-140px; background-color:white; overflow-y: scroll;"> 
     <h5><strong>Student with 3 Consecutive Absences</strong></h5> 
      <table class="table"> 
       <thead> 
        <th>Course Code-Section</th> 
        <th>Student Name</th> 
        <th>View</th> 
       </thead> 
      <tbody> 
       <?php foreach($notification->result() as $notif) 
       { 
        if($notif->Total >=3) 
        { 
        ?> 
         <tr> 
          <td><?php echo $notif->Course_Code_Section?</td> 
          <td><?php echo $notif->Student?></td> 
          <td> 
           <form action="<?php echo base_url();?>index.php/attendance/check" method="post" target="_blank"> 
            <input type="hidden" name="CID" value="<?php echo $notif->CID;?>"> 
            <button class="btn btn-xs btn-success"><i class="icon-eye-open"></i> View</button> 
           <?php echo form_close();?> 
          </td> 
         </tr> 
         </div> 
         <?php }?> 
        <?php }?> 
       </tbody> 
      </table> 
    </div> 
<?php }?> 

Hier wird die Benachrichtigung Ansicht ist, ist die Standard-Hintergrundfarbe weiß. Deshalb möchte ich, dass die Hintergrundfarbe rot wird, wenn die Bedingung erfüllt ist.

Notification View

+1

conditio Fügen Sie schließlich eine Klasse innerhalb des Tags hinzu wie 'class =" red "' dann deklarieren Sie einfach '.red {background-color;}' in Ihrem css. Hast du irgendetwas versucht, bevor du diese Frage geschrieben hast? Hast du überhaupt geforscht? Dies ist eine Frage von geringem Wert, bitte bedenken Sie, dass Sie sie löschen müssen, um die Frage auf SO zu reduzieren. – mickmackusa

+0

Was ist Ihre Bedingung - @ Ronnel Gonzales – ubm

Antwort

1

Versuchen Sie folgendes:

<?php 
$style = ''; 
if(isset($notification) && $notification->result() > 0) 
{ 
    $style = 'style="color:red"'; 
    // Put your css style property here 
} 
?> 

Html:

<div <?php echo $style ?>> 

</div> 
0

Wenn Ihr Zustand ist in PHP wahr ist, können Sie einfach diese Zeile in das Tag ein:

<tr bgcolor="#FF0000"> 

Ich weiß nicht, ob mein HTML-Code angezeigt wird oder nicht. Bitte lesen Sie diese Website:

https://www.w3schools.com/tags/att_tr_bgcolor.asp

+0

Wenn Sie Code in Antwort oder Frage Einzug um 4 Leerzeichen setzen müssen – user4419336

0

können Sie tun, wie -

<?php 
if(your condition) 
{ 
?> 
    <style> 
#your_div 
{ 
background:red !important; 
} 
</style> 
<?php 
} 
else 
{ 
?> 
    <style> 
#your_div 
{ 
background:white !important; 
} 
</style> 
<?php 
} 
?> 
0

Bitte diesen Code versuchen, ich hoffe, dass dies Ihr Zustand

<?php 
$bcolor ='background-color:white'; 
if(isset($notification) && $notification->result() >0){ 
$bcolor ='background-color:white'; 
}?> 
    <div class="panel-heading pull-right col-md-6" 
    style="height:140px; margin-top:-140px; <?php echo $bcolor ;?> overflow-y: scroll;"> 
     <h5><strong>Student with 3 Consecutive Absences</strong></h5> 
      <table class="table"> 
       <thead> 
        <th>Course Code-Section</th> 
        <th>Student Name</th> 
        <th>View</th> 
       </thead> 
      <tbody> 
       <?php foreach($notification->result() as $notif) 
       { 
        if($notif->Total >=3) 
        { 
        ?> 
         <tr> 
          <td><?php echo $notif->Course_Code_Section?</td> 
          <td><?php echo $notif->Student?></td> 
          <td> 
           <form action="<?php echo base_url();?>index.php/attendance/check" method="post" target="_blank"> 
            <input type="hidden" name="CID" value="<?php echo $notif->CID;?>"> 
            <button class="btn btn-xs btn-success"><i class="icon-eye-open"></i> View</button> 
           <?php echo form_close();?> 
          </td> 
         </tr> 
         </div> 
         <?php }?> 
        <?php }?> 
       </tbody> 
      </table> 
    </div> 
0

versuchen ist

<?php 
    $bg_red = ''; 
    if (condition) { 
     $bg_red = '<style="background-color: red;">'; 
    } 
?> 

<tr <php? echo $bg_red; ?>> 
    <td></td> 
    <td></td> 
    <td></td> 
</tr> 
Verwandte Themen