2017-02-14 42 views
-2

ul#menu li a:visited {color:yellow; }不工作

这是list.php的独立file.i已经在我的网页包含这一点,并试图突出当前页用点击的:主动,但它不是working..help我在这

<div class= "main-menu" id= "main-menu">  
      <?php include 'includes/list.php';?> 
</div> 

回答

0

a:active是您点击链接时的状态。 (http://www.w3schools.com/cssref/sel_active.asp

a:如果您点击链接之前访问过的状态。 (http://www.w3schools.com/cssref/sel_visited.asp

你可以(在这个例子中 “电流”)添加一个类来突出你的当前链接

<li><a href="first.php" class="current">first</a></li> 

并与CSS:

.current { 
    color: yellow; 
} 
+0

它不工作,我有26名单(更将在未来添加)并添加cla ss到所有链接是一个好方法? – VRG

+0

您只能将该类添加到要突出显示的链接。你可以显示不工作的代码吗? – adistoe

+0

.current { \t color:black;}

  • Last
  • VRG

    0

    如果你可以使用jQuery,然后你可以使用这个解决方案:

    js脚本应该在所有页面中都是常见的,例如first.php,second.php等。 以下是代码:

    <html> 
    <head> 
        <link rel="stylesheet" type="text/css" href="main.css"> 
        </head> 
        <style> 
        .active{ color:yellow; } 
        </style> 
        <body >  
         <?php 
           echo '<ul id="menu"> 
           <li><a href= "first.php">first</a></li> 
           <li><a href= "second.php">second</a></li> 
           <li><a href= "third.php">third</a></li> 
           </ul>'; 
         ?> 
    
    
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script> 
    
    <script type="text/javascript"> 
    $(document).ready(function() { 
    
        $('ul#menu li a').click(function() { 
         $('ul#menu li a').removeClass('active'); 
         $(this).addClass('active'); 
        }); 
    }); 
    </script> 
    </body> 
    </html> 
    

    希望,这会帮助你。

    +0

    找到我更新的答案,我希望你的问题将通过这个解决。 –

    +0

    nope仍然是一样的 – VRG

    +0

    .active类和脚注脚本应该在所有页面中都是通用的,那么只有它会工作 –

    0

    ,我发现你的问题 在L1标签,你应该检查锚标记,并检查first.php页面确实存在与否 它意味着:HREF =“../ first.php”那是你的解决方案

    但你的代码是这样的意思first.php不存在这就是为什么在CSS工作不正常

  • 第一
  • 我希望你明白我居然告诉你

    +0

    不清楚,但first.php页面存在 – VRG