How to put hover in certain links?

Discussion in 'CSS' started by kojakfilth, Feb 4, 2007.

  1. #1
    I need help on how to put hover in a certain links in dreamweaver.. Coz when i put hover all the links have the same rollover... i want rollover just in the navigation bar.. please help..
     
    kojakfilth, Feb 4, 2007 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    #navigation a:hover {
        color: green;
        }
    =========
    <ul id="navigation">
      <li><a href="some.html">some page</a></li>
    </ul>
    Code (markup):
    Will affect only the links within the navigation list.

    cheers,

    gary
     
    kk5st, Feb 4, 2007 IP
  3. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #3
    Or this, simple assigning of class to a link..
     
    Clive, Feb 5, 2007 IP
  4. kojakfilth

    kojakfilth Notable Member

    Messages:
    3,000
    Likes Received:
    213
    Best Answers:
    0
    Trophy Points:
    210
    #4
    ok thanks guys. i will try that out..
     
    kojakfilth, Feb 5, 2007 IP
  5. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'd avoid adding classes to the list items and the links in them if you have the ID assigned to the list itself. You can just reference the links directly from the list itself, as Gary was kind enough to show you.

    Do that, and your dialup and mobile users will thank you :).
     
    Dan Schulz, Feb 6, 2007 IP
  6. Smaug

    Smaug Peon

    Messages:
    374
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #6

    And you'll thank yourself later when you will changing the layout digging in old code...

    Trust me, use this priority:
    1) tags (a, span) - and sublevel tags (ul li {})
    2) classes (.link .box)
    3) IDs (#header, #leftdiv)
     
    Smaug, Feb 7, 2007 IP
  7. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I wouldn't even use names like "leftdiv" either. What if one day your "leftdiv" finds itself on the right side of the layout?
     
    Dan Schulz, Feb 7, 2007 IP
  8. Smaug

    Smaug Peon

    Messages:
    374
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #8
    yea, just an example :D
     
    Smaug, Feb 7, 2007 IP
  9. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I know. That post was for the benefit of those who may not know better :).
     
    Dan Schulz, Feb 7, 2007 IP
  10. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #10
    clyde66's question was related to limiting the hover effect to certain links. Gary has given an example which will work, however we don't necessarily need to create a list for a link as per his sample code. I would simply assign a class to the link that needs a special hover effect. Making the link part of a list is a particular situation, I would not give it as as sample for the thread starter's need.. Just to make things as easy as possible :)
     
    Clive, Feb 7, 2007 IP
  11. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #11
    Hi Clive,

    Since the OP said the links were in a nav bar, "i want rollover just in the navigation bar.. ", I worked on the inference that it was a menu, by definition, a list. If the OP were to give us a more specific description of the usage, we could offer a possibly different solution.

    cheers,

    gary
     
    kk5st, Feb 7, 2007 IP
    Clive likes this.
  12. Clive

    Clive Web Developer

    Messages:
    4,507
    Likes Received:
    297
    Best Answers:
    0
    Trophy Points:
    250
    #12
    Agree here. An URL would be a best direction for us to get a better idea of what the guy is looking for.
    Without having that, guessing is the way it usually goes :)
    I hope he picked up what's best for him.
     
    Clive, Feb 8, 2007 IP
  13. kojakfilth

    kojakfilth Notable Member

    Messages:
    3,000
    Likes Received:
    213
    Best Answers:
    0
    Trophy Points:
    210
    #13
    hi guys thanks for the advices.. i have a new questions about hover.. How can i put hover like this www.sherlockrecords.com in the navigation menu.. Like theres a link then when you point the cursor there theres an image appearing in the background of the link.. please help
     
    kojakfilth, Feb 8, 2007 IP
  14. Josh Inno

    Josh Inno Guest

    Messages:
    1,623
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #14
    In that case it is exactly the same, only instead of specifying "color" to change the text color inside of the hover style use "background-color".
     
    Josh Inno, Feb 8, 2007 IP
  15. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    436
    Best Answers:
    0
    Trophy Points:
    0
    #15
    To specify a background color, just do this:
    
    a:hover {
        background: #F0F;
    }
    
    Code (markup):
    And for background images, just replace background-color with background-image and a URL to the image.
    
    a:hover {
        background: url('image.jpg') top left no-repeat; /* you can also use repeat-x to tile it horizontally or repeat-y to tile it vertically; for both, you can simply omit no-repeat */
    }
    
    Code (markup):
    Of course, in both cases, you'll have to reference WHICH links you want. The best way to do this is to look at the parent element, and see if it has a class or ID in it (or one of its ancestors).

    For example, if your menu looks like this:
    
    <ul id="menu">
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    	<li><a href="#">Menu Item</a></li>
    </ul>
    
    Code (markup):
    Then you would target all the links in that list (and its list items) like so:
    
    #menu a {  /* this will affect ALL link states */
        /* CSS styles here */
    }
    
    #menu a:hover { /* just affects the hover state */
        /* CSS styles here */
    }
    
    Code (markup):
     
    Dan Schulz, Feb 8, 2007 IP