SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Text Color While Hover and Active Simulataneously

    I have a vertical drop down menu. The main category link text is Color A and the background is white. On hover, text changes to Color B and the background changes to Color C. When the link is active, the text changes to Color C and background white. My problem is when I again hover the link while active, I want the background Color C and the text Color B, same sequence as hover state of inactive link. Essentially I want hover inactive link and hover active link to be the same when both are in use.

    Link Inactive: Text Color A, Background White
    Hover: Link Text Color B, Background Color C
    Active: Link Text Color C, Background White
    Hover/Active: Text Color B, Background Color C


    I hope this makes sense. If anyone can tell me if this is possible I would greatly appreciate it. Below is my code, I only included relevant code:

    .menu > li > a {
    color: #CB6C00;
    }
    .menu > li > a span {
    background: #FFFFFF;
    }
    .menu > li > a:hover {
    background-color: #008590;
    color: #FFFFFF;
    }
    .menu > li > a.active { (I want a hover here to be text #FFFFFF and background #008590, but of course text is already #008590.)
    color: #008590;
    }

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,319
    Mentioned
    462 Post(s)
    Tagged
    8 Thread(s)
    Have you tried this?

    Code:
    .menu > li > a.active:hover {
      color: #fff;
      background: #008590;
    }

  3. #3
    SitePoint Member
    Join Date
    Sep 2012
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried it but did not work until I realized I didn't change the text color in the non-hover active state. Thank you for the help!

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,869
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The only way to achieve an active state without hover applying is if the keyboard has been used to give the field the focus and then the enter key pressed to make it active.

    Are you sure that you are using the keyboard to tab to the field and then pressing enter in order to set the active state without first setting the hover state - which you'd do by moving the mouse over it (where you'd depress a mouse button to set it active).

    Also you need to remember that it only stays active until the key is released - once you release the key it returns to the hover or focus state.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Location
    Glasgow, Scotland
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a:hover,a:active { /* rules */ }

  6. #6
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,319
    Mentioned
    462 Post(s)
    Tagged
    8 Thread(s)
    The OP has a class of "active" applied to a menu item when it is the currently selected page. This is not an issue over the :active pseudo class. Ideally, to avoid confusion, it's better to use a class of "current" (or similar).


Bookmarks

Posting Permissions

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