所以这一直让我疯狂,我想要的只是在相应的页面上突出显示当前的li,
请原谅我们的代码,
HTML
<div id="layout">
<!-- Menu toggle -->
<a href="#menu" id="menuLink" class="menu-link active">
<span></span>
</a>
<div id="menu">
<div class="pure-menu pure-menu-open">
<a class="pure-menu-heading" href="pure.html">Nathaniel Harman</a>
<ul class="nav">
<li>
<a href="software.html">
<span class="icon-macintosh" style="vertical-align: middle"></span>SOFTWARE</a>
</li>
<li>
<a href="frameworks.html">
<span class="icon-painting-roll-streamline" style="vertical-align: middle"></span>FRAMEWORKS</a>
</li>
<li>
<a href="lang.html">
<span class="icon-ink-pen-streamline" style="vertical-align: middle"></span>LANGUAGES</a>
</li>
<li>
<a href="projects.html">
<span class="icon-crop-streamline" style="vertical-align: middle"></span>PROJECTS</a>
</li>
<li>
<a href="exp.html">
<span class="icon-monocle-mustache-streamline" style="vertical-align: middle"></span>EXPERINECE</a>
</li>
<li>
<a href="production.html">
<span class="icon-design-graphic-tablet-streamline-tablet" style="vertical-align: middle"></span>IN PRODUCTION</a>
</li>
<li>
<a href="development.html">
<span class="icon-barista-coffee-espresso-streamline" style="vertical-align: middle"></span>IN DEVELOPMENT</a>
</li>
<li>
<a href="contact.html">
<span class="icon-map-streamline-user" style="vertical-align: middle"></span>CONTACT</a>
</li>
</ul>
CSS
#menu {
margin-left: -200px; /* "#menu" width */
width: 200px;
position: fixed;
top: 0;
left: 0;
bottom: 0;
z-index: 1000; /* so the menu or its navicon stays above all content */
background: #191818;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
#menu a {
color: #999;
border: none;
padding: 0.6em 0 0.6em 0.6em;
}
#menu .pure-menu,
#menu .pure-menu ul {
border: none;
background: transparent;
}
#menu .pure-menu ul,
#menu .pure-menu .menu-item-divided {
border-top: 1px solid #333;
}
#menu .pure-menu li a:hover,
#menu .pure-menu li a:focus,
#menu .pure-menu span:hover{
background: #333;
color:#fff;
}
#menu .pure-menu-selected,
#menu .pure-menu-heading {
background: #909090;
}
#menu .pure-menu-selected a {
color: #fff;
}
#menu .pure-menu-heading {
font-size: 110%;
color: #fff;
margin: 0;
}
.menu-link {
position: fixed;
display: block; /* show this only on small screens */
top: 0;
left: 0; /* "#menu width" */
background: #000;
background: rgba(0,0,0,0.7);
font-size: 10px; /* change this value to increase/decrease button size */
z-index: 10;
width: 2em;
height: auto;
padding: 2.1em 1.6em;
}
.menu-link:hover,
.menu-link:focus {
background: #000;
}
.menu-link span {
position: relative;
display: block;
}
.menu-link span,
.menu-link span:before,
.menu-link span:after {
background-color: #fff;
width: 100%;
height: 0.2em;
}
.menu-link span:before,
.menu-link span:after {
position: absolute;
margin-top: -0.6em;
content: " ";
}
.menu-link span:after {
margin-top: 0.6em;
}
任何帮助都会很棒我无法弄清楚我哪里出错了,因为你可以看到我使用Pure CSS框架
答案 0 :(得分:1)
最简单的方法是创建一个类,让我们说current
,并将其分配给每个页面上的li
元素。例如,您的software.html
文件将如下所示:
<li class="current">
<a href="software.html">
<span ...></span>SOFTWARE</a>
</li>
<li>
<a href="frameworks.html">
<span ...></span>FRAMEWORKS</a>
</li>
虽然您的frameworks.html
文件如下所示:
<li>
<a href="software.html">
<span ...></span>SOFTWARE</a>
</li>
<li class="current">
<a href="frameworks.html">
<span ...></span>FRAMEWORKS</a>
</li>
然后相应地设置.current
样式
答案 1 :(得分:0)
您需要对您的每个LI进行身份识别和分类:
<li id="item1" class="menuitemOff">
然后在你的CSS中,创建&#34; off&#34;国家和&#34;在&#34;你的李的状态。 为每个设置正确的状态。
如果您想稍后使用JavaScript更改ID,则需要这些ID。
答案 2 :(得分:0)
你可以通过在DOM ready上添加它来动态地完成它:
$('.nav li').filter(function(){
var page = $(this).children('a').attr('href');
var url = window.location.pathname
return (url===page);
}).addClass('pure-menu-selected');
您可能需要调整url
变量,具体取决于您的设置。
以下是一个简单示例:http://jsfiddle.net/2yLY8/