简体   繁体   English

当前页面链接未突出显示

[英]Current page link not highlighted

I am building a webpage with a fixed side navigation. 我正在建立一个带有固定侧面导航的网页。 However the current page will not highlight the desired color. 但是,当前页面不会突出显示所需的颜色。 I have a "nav-item" on all of the nav links, and a "nav-item current" on the current page. 我在所有导航链接上都有一个“导航项”,在当前页面上有一个“导航项当前”。 I beleive the html is fine, and I think the css is fine as well, but I don't get why it won't highlight. 我相信html很好,而且我认为CSS也很好,但是我不明白为什么它不会突出显示。

 .nav-container { display: block; clear: left; padding-top: 35px; } .navigation { width: 75%; margin: auto; clear: left; } .current { color: #36d9d3; } .nav-item { text-decoration: none; box-sizing: border-box; clear: left; float: left; display: block; margin: 10px; font-size: 20px; color: black; font-family: 'Raleway', sans-serif; -webkit-transition: 200ms color ease; } .nav-item:hover { color: grey; } 
 <div class="nav-container"> <nav class="navigation"> <a class="nav-item current" href="#">Illustrations</a> <a class="nav-item" href="#">Designs</a> <a class="nav-item" href="#">Artwork</a> <a class="nav-item" href="#">Photography</a> </nav> </div> 

Add !important to your colour for current as your style is getting over ridden. 随着样式的变化,请在颜色中加上!important作为current颜色。 For styles defined in external stylesheets, the priority is in the order from bottom to the top for two identical attributes 对于在外部样式表中定义的样式,对于两个相同的属性,优先级按从下到上的顺序排列

 .nav-container { display: block; clear: left; padding-top: 35px; } .navigation { width: 75%; margin: auto; clear: left; } .current { color: #36d9d3 !important; } .nav-item { text-decoration: none; box-sizing: border-box; clear: left; float: left; display: block; margin: 10px; font-size: 20px; color: black; font-family: 'Raleway', sans-serif; -webkit-transition: 200ms color ease; } .nav-item:hover { color: grey; } 
 <div class="nav-container"> <nav class="navigation"> <a class="nav-item current" href="#">Illustrations</a> <a class="nav-item" href="#">Designs</a> <a class="nav-item" href="#">Artwork</a> <a class="nav-item" href="#">Photography</a> </nav> </div> 

look this and get an idea. 看看这个,得到一个主意。

 $(document).on("click", 'ul li', function(){ $('ul li').removeClass('active'); $(this).addClass('active'); }); 
 a { color:#000; text-decoration:none; } a:hover { text-decoration:underline; } a:visited { color:#000; } .nav { padding:10px; border:solid 1px #c0c0c0; border-radius:5px; float:left; } .nav li { list-style-type:none; float:left; margin:0 10px; } .nav li a { text-align:center; width:55px; float:left; } .nav li.active { background-color:green; } .nav li.active a { color:#fff; font-weight:bold; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <ul class="nav"> <li><a href="#tab1">Menu 01</a> </li> <li>|</li> <li><a href="#tab2">Menu 02</a> </li> <li>|</li> <li><a href="#tab3">Menu 03</a> </li> </ul> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM