javascript - How to change the current link color in navigation bar -
javascript - How to change the current link color in navigation bar -
how can specify background color link "block" in navigation bar selected (clicked)?
the thought navigation bar positioned top of page , because links targeted iframe, main index html doesn't refresh. can't find way solve this. can done css or need javascript or else that?
thanks in advance!
html:
<table> <tr> <td> <div class="menuint"> <ul> <li><a href="page1.html" target="ifrm"><h1>link 1</h1></a></li> <li><a href="page2.html" target="ifrm"><h1>link 2</h1></a></li> <li><a href="page3.html" target="ifrm"><h1>link 3</h1></a></li> <li><a href="page4.html" target="ifrm"><h1>link 4</h1></a></li> <li><a href="page5.html" target="ifrm"><h1>link 5</h1></a></li> <li><a href="page6.html" target="ifrm"><h1>link 6</h1></a></li> </ul> </div> </td> </tr> </table>
and css:
.menuint ul { list-style-type: none; margin: 0; padding: 0; overflow: hidden; } .menuint li { float: left; padding: 0px 0px 0px 1px; background-color: #414141; border: 1px solid black; border-right-style: none; border-top-style: none; border-bottom-style: none; } .menuint a:link, a:visited { display: block; width: 127px; padding: 6px 0px 6px 0px; text-decoration: none; /* background-image: url("img/testbgrsmall.png"); */ } .menuint a:hover, a:active { background-color: #7a991a; } h1 { color: #ffffff; text-transform: uppercase; font-weight: bold; text-decoration: none; font-size: 18px; letter-spacing: 0px; }
demo: http://jsfiddle.net/ag47d/3/
here suggestion using code , comments
note added data-id
, how used $("#" + $(this).data('id'))
class="snippet-code-js lang-js prettyprint-override">$(function() { $('#nav li a').click(function() { $('#nav li').removeclass(); $("#" + $(this).data('id')).addclass('active'); }); });
class="snippet-code-css lang-css prettyprint-override">.navbar #nav > .active > { color: red; background-color: greenish }
class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="navbar"> <div class="navbar-fixed-top"> <div class="container" style="width: auto;"> <div class="nav-collapse" id="nav-collapse"> <ul class="nav" id="nav"> <li id="home"><a href="home.html" data-id="home" target="ifrm">home</a></li> <li id="skill"><a href="skill.html" data-id="skill" target="ifrm">skill</a></li> <li id="research"><a href="research.html" data-id="research" target="ifrm">research</a></li> <li id="link"><a href="link.html" data-id="link" target="ifrm">link</a></li> </ul> </div> </div> </div> </div> <iframe name="ifrm"></iframe>
javascript css css3
Comments
Post a Comment