Change a PHP background colour to a CSS call

2019-09-11 00:01发布

I am no coder but am trying to take anything CSS related out of a php file but require a little help.

How can I re write the below code to get the bgcolor from an external CSS instead of the php doing the job

I just want the bellow rewriting to include the CSS class instead of the code actualy making the color.

Hope you understand what I am saying

first bit of code

$bgcolour = ($k % 2) ? 'bgcolor="#FFFEEE"' : '';

Second bit of code

'ROWCOLOUR' => ($row['highlighted'] == 'y') ? 'bgcolor="#fea100"' : $bgcolour,

2条回答
Juvenile、少年°
2楼-- · 2019-09-11 00:44

CSS:

.fffeee {
  background-color: #FFFEEE;
}

.fea100 {
  background-color: #FEA100;
}

PHP:

$cssClass = ($k % 2 == 0 && $row['highlighted'] != 'y') ? 'fffeee' : 'fea100';

'ROWCOLOUR' => 'class="' . $cssClass . '"',
查看更多
smile是对你的礼貌
3楼-- · 2019-09-11 00:51
<style>
    .mouseoverbg{
        background-color : #eeefff;
    }
    .oddrowbg{
            background-color : #fffeee;
    }
    .evenrowbg{
            background-color : #fea100;
    }
</style>
<table>
<?php
$ni = 5;
for($i=0 ; $i<$ni; $i++)
{
    $bgcolor = ($i%2)?"evenrowbg" : "oddrowbg";
    ?>
    <tr onmouseover="this.className='mouseoverbg'"  onmouseout="this.className='<?php echo $bgcolor?>'" class="<?php echo $bgcolor?>">
    <td><?php echo $i;?></td>
    </tr>
<?php 
}?>
</table>

Try this code it may help you.

查看更多
登录 后发表回答