How to change link color in div?

Discussion in 'HTML & Website Design' started by wryfhk22, May 31, 2011.

  1. #1
    How do you change the link color in one specific div and another color in antother div ?

    Thanks !
     
    wryfhk22, May 31, 2011 IP
  2. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #2
    1. Assign class to each link
    2. Assign class to each div

    Example for 1:

    Markup:
    
    <div><!-- First div -->
    <a class="link-type-a" href="#">Click Here</a>
    </div>
    <div><!-- Second div -->
    <a class="link-type-b" href="#">Click Here</a>
    </div>
    
    Code (markup):
    CSS:
    
    a .link-type-a{color:#ff0000}
    a .link-type-b{color:#00000}
    
    Code (markup):
    Example for 2:

    Markup:
    
    <div class="link-type-a"><!-- First div -->
    <a href="#">Click Here</a>
    </div>
    <div  class="link-type-b" ><!-- Second div -->
    <a href="#">Click Here</a>
    </div>
    
    Code (markup):
    CSS:
    
    .link-type-a a{color:#ff0000}
    .link-type-b a{color:#00000}
    
    Code (markup):
    Advantage 2 over 1 is, if there are more than 1 links, all links in specified within a div will have the specific color rather assigning class each time for each number of links.
     
    radiant_luv, Jun 1, 2011 IP
  3. jacksamwhite

    jacksamwhite Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Assign different class of CSS to different div and in this way you can easily change the colors of links in div.
     
    jacksamwhite, Jun 1, 2011 IP
  4. Guru_101

    Guru_101 Member

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    That was like the WROST example ever.

    The way you do it in a declared div class or id...

    
    #whatever a:link, 
    #whatever a:visited, 
    #whatever a:hover { 
    [B] color: #DDDDDD; 
     text-decoration: none; [/B]
    } 
    Code (markup):
    Change everything you want inside the bold writing and change the "whatever" to what you want.
     
    Guru_101, Jun 1, 2011 IP
  5. Netizenx

    Netizenx Greenhorn

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #5

    Don't forget to refer to your div class in your HTML like thus:

    <DIV CLASS="whatever">content and links here</DIV>
     
    Last edited: Jun 2, 2011
    Netizenx, Jun 2, 2011 IP
  6. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Perhaps take a good look at solution 2. It's the same as two of you referring. :)
     
    radiant_luv, Jun 2, 2011 IP
  7. radiant_luv

    radiant_luv Peon

    Messages:
    1,327
    Likes Received:
    34
    Best Answers:
    1
    Trophy Points:
    0
    #7
    Selectors needs to be within " "
     
    radiant_luv, Jun 2, 2011 IP
  8. designmonkey

    designmonkey Peon

    Messages:
    70
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You could set different class for each divs, then assign the a child ( include the pseudo if you will ) for colors, but that would be bad practice since it'll slow down the css rendering. Also it'll get quite complicated if you're working on a huge site/web-apps.

    Better option is to define different classes for each a you want to style.
    check this for reference for best efficient css : https://developer.mozilla.org/en/Writing_Efficient_CSS
     
    designmonkey, Jun 2, 2011 IP
  9. Netizenx

    Netizenx Greenhorn

    Messages:
    41
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    18
    #9
    My bad. I edited to include quotation marks. Thanks for the heads-up.
     
    Netizenx, Jun 2, 2011 IP