使用CSS突出显示活动菜单链接

时间:2014-08-16 05:42:13

标签: html css

我正在使用CSS突出显示与访问者当前所在页面对应的菜单上的链接,以便他们知道他们在网站中的位置。

我已将此作为指南Active Menu Highlight CSS 但它仍然没有用。

有人能找到我错的地方吗? 提前谢谢!

HTML

<ul id="nav">    
    <li class="editorial"><a class="nav" href="editorial.html">EDITORIAL</a></li>
    <li class="places"><a class="nav" href="places.html">PLACES</a></li>
    <li class="people"><a class="nav" href="people.html">PEOPLE</a></li>
    <li class="architecture"><a class="nav" href="architecture.html">ARCHITECTURE</a></li>
    <li class="projects"><a class="nav" href="projects.html">PROJECTS</a></li>
    <li class="published"><a class="nav" href="published.html">PUBLISHED</a></li>
</ul>

我还添加了一个

<body class="editorial">
<body class="places">
每页都有

......等。

CSS

#nav .nav:hover,
body.editorial li.editorial,
body.places li.places
body.people li.people 
body.architecture li.architecture
body.projects li.projects
body.published li.published { 
    background:#FFFF00;
    color:#000;
}

#nav .nav:hover a.nav,
body.editorial li.editorial a.nav,
body.places li.places a.nav
body.people li.people a.nav
body.architecture li.architecture a.nav
body.projects li.projects a.nav
body.published li.published a.nav{ 
    background:#FFFF00;
    color:#000; 
}

1 个答案:

答案 0 :(得分:2)

它没有用,因为你忘了用逗号分隔选择器:

#nav .nav:hover a.nav,
body.editorial li.editorial a.nav,
body.places li.places a.nav,               /* <== forgotten comma */
body.people li.people a.nav,               /* <== forgotten comma */
body.architecture li.architecture a.nav,   /* <== forgotten comma */
body.projects li.projects a.nav,           /* <== forgotten comma */
body.published li.published a.nav { 
  background:#FFFF00;
  color:#000;
}

检查这个小提琴:http://jsfiddle.net/arnellebalane/0rq291ds/