How to apply one style to only certain texts?

Discussion in 'CSS' started by ljCharlie, Feb 24, 2009.

  1. #1
    I have the following CSS code for my hyperlink texts.

    .staffFullName a, a:link, a:visited, a:active
    {
        color: #000066;
        text-decoration: none;
        font-size: 18px;
    }
    .staffFullName a:hover 
    {
        color: Blue;
        text-decoration: underline;
    }
    Code (markup):
    In my code behind, I have this:

    <a class="staffFullName" href="staffProfile.aspx?">Staff Profile</a>

    And here's the problem. Everything in the page changes font size to 18 and the hover does not work anything. I only want the link to change font size and hover to apply to. Why the whole page now uses the CSS style that I strictly specify in the class of the hyperlink? Any suggestion on how to resolve this issue is much appreciated.
     
    ljCharlie, Feb 24, 2009 IP
  2. awatson

    awatson Active Member

    Messages:
    112
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    If you look at your first line, you're setting that stuff for a:link, a:visited and a:active globally - I suspect you want it to look like:

    
    .staffFullName a, .staffFullName a:link, .staffFullName a:visited, .staffFullName a:active {
    
    PHP:
    In other words the ".staffFullName" in the first selector doesn't apply to the the other items after the first comma - you need to be specific. Hope that helps.
     
    awatson, Feb 24, 2009 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    Almost there. The class applies to the anchor itself, while the css selectors apply to
    .staffFullName a, /* any anchor descended from .staffFullName, of which there are none */ 
    a:link,   /* this applies to all links except those that are visited /
    a:visited,   /* and this get the visited links */ 
    a:active   /* this gets all active enter keydowns when the link has focus, and mousedowns */
    {
        color: #000066;
        text-decoration: none;
        font-size: 18px;
    }
    .staffFullName a:hover  /* this get hovered links that are descended from .staff..., in other words, never */ 
    {
        color: Blue;
        text-decoration: underline;
    }
    Code (markup):
    Try this instead:
    a.staffFullName {
        color: #006;
        font-size: 18px;
        text-decoration: none;
        }
    
    a.staffFullName:hover {
      color: blue;
      text-decoration: underline;
      }
    Code (markup):
    cheers,

    gary
     
    kk5st, Feb 24, 2009 IP
  4. ljCharlie

    ljCharlie Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Thanks! It works.
     
    ljCharlie, Feb 27, 2009 IP