
- Forum
- Programming Talk
- Html
- How to set current menu style
How to set current menu style
This is a discussion on How to set current menu style within the Html forums, part of the Programming Talk category; Hi, iam try to set style to current menu,how to set style to current menu? iam write focus attribute in ...
-
How to set current menu style
Hi,
iam try to set style to current menu,how to set style to current menu? iam write focus attribute in css.but its not working.any one help me.
HTml Code:
HTML Code:<div class="urbangreymenu"> <ul> <li><a href="#">Design</a></li> <li><a href="#">Analysis</a></li> <li><a href="#">FMEA</a></li> <li><a href="#">CAD</a></li> <li><a href="#">NPI</a></li> <li><a href="#">Contract</a></li> </ul> </div>
CSS Code :
HTML Code:<style type="text/css"> .urbangreymenu{ width: 210px; /*width of menu*/ margin-top:25px; } .urbangreymenu .headerbar{ font: bold 13px Verdana; color: white; background: #606060 url(media/arrowstop.gif) no-repeat 8px 6px; /*last 2 values are the x and y coordinates of bullet image*/ margin-bottom: 0; /*bottom spacing between header and rest of content*/ text-transform: uppercase; padding: 7px 0 7px 31px; /*31px is left indentation of header text*/ } .urbangreymenu ul{ list-style-type: none; margin: 0; padding: 0; margin-bottom: 0; /*bottom spacing between each UL and rest of content*/ } .urbangreymenu ul li{ padding-bottom: 2px; /*bottom spacing between menu items*/ } .urbangreymenu ul li a{ font: normal 12px Arial; color: black; display: block; padding: 7px 0; line-height: 17px; padding-right: 15px; /*link text is indented 8px*/ text-decoration: none; text-align:right; } .urbangreymenu ul li a:focus { padding-right: 15px; color: red; background-image:url(images/lefthover.jpg); background-repeat:no-repeat; } #current{ padding-right: 15px; color: black; background-image:url(images/lefthover.jpg); background-repeat:no-repeat; } .urbangreymenu ul li a:hover{ /*hover state CSS*/ padding-right: 15px; color: red; font-weight:bold; background-image:url(images/lefthover.jpg); background-repeat:no-repeat; } </style>
Thanks,
Megabyte
Last edited by megabyte; 05-22-2009 at 03:26 AM.
-
Use this Javascript Function
add this java script in header section.willl you change your CSS id in java script whatever you want
HTML Code:function extractPageName(hrefString) { var arr = hrefString.split('/'); return (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase(); } function setActiveMenu(arr, crtPage) { for (var i=0; i
Your HTML code set like this
HTML Code:<div id="urbangreymenu"> <ul> <li><a href="#">Text</a></li> <li><a href="#">Text</a></li> <li><a href="#">Text</a></li> <li><a href="#">Text</a></li> <li><a href="#">NPI</a></li> <li><a href="#">Text</a></li> </ul> <script language="javascript">setPage()</script> </div>
-
code is missing in above post
PHP Code:function extractPageName(hrefString)
{
var arr = hrefString.split('/');
return (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}
function setActiveMenu(arr, crtPage)
{
for (var i=0; i<arr.length; i++)
{
if(extractPageName(arr[i].href) == crtPage)
{
if (arr[i].parentNode.tagName != "DIV")
{
arr[i].className = "current";
arr[i].parentNode.className = "current";
}
}
}
}
function setPage()
{
hrefString = document.location.href ? document.location.href : document.location;
if (document.getElementById("urbangreymenu")!=null)
setActiveMenu(document.getElementById("urbangreymenu").getElementsByTagName("a"), extractPageName(hrefString));
}
-
Sponsored Ads

Reply With Quote





