我试图根据我所在的页面突出显示导航栏,例如:
到
如您所见,我移动到的页面已突出显示。我怎样才能在代码中做到这一点?
<div class="navbar" id="navbar_welcome">
<a href="index.php?action=home" class="active"><i class="fas fa-home"></i> Home</a>
<a href="index.php?action=home"><i class="fas fa-chart-line"></i> History</a>
<a href="index.php?action=setting"><i class="fas fa-user"></i> Profile</a>
</div>
最佳答案
使用您的 $_GET 变量来回显内联 background-style
页面生成的属性。
<div class="navbar" id="navbar_welcome">
<a href="index.php?action=home" class="active">
<i class="fas fa-home" <?php if ($_GET['action']=='home') { echo 'style="background-color: grey;"'; }?>></i> Home
</a>
<a href="index.php?action=hsitory">
<i class="fas fa-chart-line" <?php if ($_GET['action']=='history') { echo 'style="background-color: grey;"'; }?>></i> History
</a>
<a href="index.php?action=setting">
<i class="fas fa-user" <?php if ($_GET['action']=='setting') { echo 'style="background-color: grey;"'; }?>></i> Profile
</a>
</div>
您也可以在 <style>
中做类似的事情 header 中的标签,两者都有效。
关于javascript - 如何根据我所在的页面突出显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58982632/