Exforsys
+ Reply to Thread
Results 1 to 3 of 3

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 ...

  1. #1
    megabyte is offline Junior Member Array
    Join Date
    Nov 2006
    Answers
    23

    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.

  2. #2
    chowexfo is offline Junior Member Array
    Join Date
    Mar 2009
    Answers
    11
    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>



  3. #3
    chowexfo is offline Junior Member Array
    Join Date
    Mar 2009
    Answers
    11
    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(arrcrtPage)
    {
    for (var 
    i=0i<arr.lengthi++)
        {
            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



Latest Article

Network Security Risk Assessment and Measurement

Read More...