当前位置: 动力学知识库 > 问答 > 编程问答 >

suggest proper conditional statement to fade tabs with CSS via PHP

问题描述:

I want to change the class of two tabs via PHP, but I am stuck in basic condition. here is my code:

CSS

.myinfo { background-color:black }

.deactive { background-color : white }

HTML

<li class="myinfo <?=$deact?>">

<a href="myaccount.php?<?=$qry_str?>" >My Info</a>

</li>

<li class="myinfo <?=$deact?>">

<a href="myaccount.php?mycontacts&<?=$qry_str?>">My Contacts</a>

</li>

What I need is

if $_GET['mycontacts'] is active

then My Info link should have class deactive

otherwise My Contacs link should have class deactive

I tried this:

if (isset($_GET['mycontacts'])){

$deact ='deactive';

}

But it did not succeed. Please help to write this condition (I think a one line ternary condition could work).

网友答案:

Try this:

<li class="myinfo <?php echo ($_GET['mycontacts'] === 'active' ? 'deactive' : '') ?>">
  <a href="myaccount.php?<?=$qry_str?>" >My Info</a>
</li>
<li class="myinfo <?php echo ($_GET['mycontacts'] !== 'active' ? 'deactive' : '') ?>">
  <a href="myaccount.php?mycontacts&<?=$qry_str?>">My Contacts</a>
</li>

By the way I hate php short tags! Personal preference...

分享给朋友:
您可能感兴趣的文章:
随机阅读: