-1

I have two pages and included the navigation in both of them so it makes it easier to edit it once than doing it in both. But now I am very unsure how to implement the class active, which shows which you are in (highlights) with css. This is the code:

<li><a href="../rapport/index.php" class='rapport' >Rapport</a></li> 
<li><a href="../diagram/index.php" class='diagram' >Diagram</a></li>    

EDIT: This is the css for the image and css and the icon. In blade I did this to make it active:

<li  class='pil  {{ ($aktiv == 'sok') ? 'active' : '' }}'> <a class='sok' {{HTML::linkRoute('sok','Søk')}}</a> </li>  

CSS:

.navbar-default .navbar-nav>.active>a.rapport:before,
.navbar-nav>li>a.rapport:before { background-image: url('../images/top3.png'); }

.navbar-default .navbar-nav>.active>a.diagram:before,
.navbar-nav>li>a.diagram:before { background-image: url('../images/top2.png'); }
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
user3270211
  • 915
  • 4
  • 20
  • 42
  • possible duplicate of [Bootstrap CSS Active Navigation](http://stackoverflow.com/questions/9301507/bootstrap-css-active-navigation) – Paulie_D Apr 22 '14 at 09:27
  • possible duplicate of SO many other CSS navigation threads! – Fizor Apr 22 '14 at 09:28

3 Answers3

1

Add a variable $page to your page. For example

In Rapport page

<?php
$page = 'Rapport';
include('header.php');
?>

In diagram page

<?php
$page = 'diagram';
include('header.php');
?>

header.php

<li><a href="../rapport/index.php" class="<?php if($page=='Rapport'){echo 'active';}?>" >Rapport</a></li>
<li><a href="../diagram/index.php" class="<?php if($page=='diagram'){echo 'active';}?>">Diagram</a></li>
Vishnuraj V
  • 2,819
  • 3
  • 19
  • 23
0

If you have many pages and don't want to use jQuery or PHP then add active class to current page

<li><a href="../rapport/index.php" class="rapport active">Rapport</a></li>
<li><a href="../diagram/index.php" class="diagram">Diagram</a></li>

.active {
  background: red;
  color: #fff;
}

remember to change active link class according to active page.


Ok after question updates I'll provide PHP solution which is

<li><a href="index.php" <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="active"'; ?>>Link Text</a></li>

or jQuery solution

<li><a href="index.php">Link Text</a></li>

<script>
  $('li a[href="'+window.location.pathname.split('/').pop()+'"]').addClass('active');
</script>
Milan and Friends
  • 5,560
  • 1
  • 20
  • 28
0
Please find the CSS code:

#navigation{ 
width:100%;
height:35px;
}

#menu {
width:580px;
height:35px;
}

#menu li{
list-style-type:none;
float:left;
}

#menu a {
height:35px;
color:#FFFFFF;
}

#menu a:hover{
color: #FFFFFF;
text-decoration:none;
}

.active {
color:#000000;
text-decoration:none;
font-family: Calibri;
font-size: 14px;
}

HTML code:

When rapport/index.php page open make sure your li should be active something like following

<div id="navigation">
<li class="active"><a href="../rapport/index.php" class="rapport active">Rapport</a></li>
<li><a href="../diagram/index.php" class="diagram">Diagram</a></li>
</div>

And when diagram/index.php open then use following

<div id="navigation">
<li><a href="../rapport/index.php" class="rapport active">Rapport</a></li>
<li class="active"><a href="../diagram/index.php" class="diagram">Diagram</a></li>
</div>
Madhuri
  • 158
  • 1
  • 8