Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts

    Link inside an <li>, need to change its color on hover

    I have this code
    Code:
    <li class="mainMenuLi" onmouseover="showSub(1, 'block', this)" onmouseout="showSub(1, 'none', this)"><a href="/221Print"><span>221 Printing</span></a></li>
    I need it so when i hover over the li the LI's background colour changes and the links text colour changes. The background colour changes fine.

    Code:
    #mainMenu li
    {
    	padding:2px;
    	border:1px solid #de0088;
    	border-right:none;
    	width:195px;
    	background-color:#ffe306;
    }
    
    #mainMenu li:hover
    {
    	background-color:#de0088;
    	color:#FFFF00;
    	border:1px solid #FFFF00;
    	border-right:none;
    }
    Its for a drop down menu and when i try #mainMenu li:hover, #mainMenu a:hover it doesnt work, because when im hovering over a sub menu the mainmenus background color stays changed but the text colour reverts to normal. Does anyone know a way i can get the text colour to stay and the desired hover colour? If i remove the <a>...</a> and just have the text the property 'color:' works, can i make the link colour use the 'color:' preoperty?
    Last edited by tomharto; 07-25-2011 at 09:51 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2011
    Location
    India
    Posts
    496
    Thanks
    3
    Thanked 57 Times in 56 Posts
    You need to create a class .active assign it to menu which is clicked.


  • #3
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    The drop down menus work on mouseover not mouseclick, would active still work for that?

  • #4
    Regular Coder
    Join Date
    Jul 2011
    Location
    India
    Posts
    496
    Thanks
    3
    Thanked 57 Times in 56 Posts
    You want keep its color changed even after mouse out?

    If this is so.. then use jquery

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Well when the sub menus' are display the main menu's background colour stays on the :hover colour and i need the links to stay the :hover colour too but they change back, i didnt wanna use JS but it seems im gonna have to :P

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The drop down menus work on mouseover not mouseclick, would active still work for that?

  • #7
    Regular Coder
    Join Date
    Jul 2011
    Location
    India
    Posts
    496
    Thanks
    3
    Thanked 57 Times in 56 Posts
    You have to use jquery only... and its not difficult to use.

    share your navigation HTML and CSS code, I ll try to write jquery for you


    Last edited by vikram1vicky; 07-25-2011 at 11:52 AM.

  • #8
    Regular Coder
    Join Date
    Jul 2010
    Location
    Sheffield
    Posts
    822
    Thanks
    93
    Thanked 18 Times in 18 Posts
    Code:
    .active
    {
    	color:#FFFF00;
    	background-color:#999999;
    	font-size:3em;
    }
    Code:
    function showSub(num, what, Link)
    {
    	var Elem = document.getElementById("sub"+num);
    	Elem.style.display = what;
    	var linK = document.getElementById(Link);
    	linK.setAttribute("class", "active");
    }
    Code:
    <li class="mainMenuLi" onmouseover="showSub(1, 'block', 'main1')" onmouseout="showSub(1, 'none', 'main1')"><a id="main1" href="/221Print"><span>221 Printing</span></a></li>
    For some reason when i try that code the links background colour and text size change but the colour doesnt, anyone see why?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •