www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Links of a different color

  1. #1
    Join Date
    Feb 2006
    Location
    Pennsylvania
    Posts
    153

    resolved [RESOLVED] Links of a different color

    I'm having a brain issue right now and just can't figure out how to have my links different colors on the page.

    The primary links will be one color however I would like some other links to be a different color.

    Can someone help me please?

  2. #2
    Join Date
    Dec 2005
    Location
    American, living in Toronto, ON. CANADA
    Posts
    6,746
    HTML Code:
    <!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title> New Document </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="Generator" content="" />
    <meta name="Author" content="Joel A. Burdick" />
    <meta name="Keywords" content="" />
    <meta name="Description" content="" />
    <meta name="copyright" content="None. Free to use" />
    <style type="text/css">
    body, html   {margin:0; padding:0; border:0;} /* Re-sets IE to "zero" for these values */
    
    body	{background-color:#cecece; margin:50px; } /* Give the body some nice margin and background color */
    ul li	{margin-bottom:10px; list-style-type:none;}/*space out the UL and LI's and remove the "disc" */
    
    
    
    a:link	{color:blue} /*First view of page*/
    a:visited {color:green;}/*Visited*/
    a:hover {color:red;}/*mouse tool over link*/
    a:active {color:white;}/*mouse-down on link*/
    
    a:link.other_colors {color:black;} /*First view of page*/
    a:visited.other_colors {color:purple;}/*Visited*/
    a:hover.other_colors {color:yellow;}/*mouse tool over link*/
    a:active.other_colors {color:olive;}/*mouse-down on link*/
    
    </style>
    </head>
    
    <body>
    
    <h1>The stylesheet:</h1>
    a:link	{color:blue}
    a:visited {color:green;}
    a:hover {color:red;}
    a:active {color:white;}
    
    a:link.other_colors {color:black;}
    a:visited.other_colors {color:purple;}
    a:hover.other_colors {color:yellow;}
    a:active.other_colors {color:olive;}</pre>
    
    
    <div style="width:300px; border-top:4px double green;">
    <p style="padding-top:6px;">This list use 'regular' link data, from style sheet</p>
    <ul>
    <li><a href="#">link number 1</a></li>
    <li><a href="#">link number 2</a></li>
    <li><a href="#">link number 3</a></li>
    </ul>
    </div>
    
    <div style="width:400px; margin-top:25px;">
    <p>This list use <strong>class="other colors"</strong> link data, from style sheet
    <br />
    Note that there is NO SPACE between text in "other_colors"
    <br />
    "a:link.other_colors" is correct, "a:link(space).other_colors" will NOT work </p>
    <ul>
    <li><a class="other_colors" href="#">This link is not blue</a></li>
    <li><a class="other_colors" href="#">This link is not blue either</a></li>
    <li><a class="other_colors" href="#">Nor is this link blue</a></li>
    <ul>
    </div>
    
    
    </body>
    </html>
    I created a STYLE that makes "all hyperlinks" normally be BLACK on first page visit and GREEN if you've visited that page-link before ("visited"), RED on-hover state and WHITE when you click-and-hold the hyperlink.

    To have other link behave differently, you first set-up your links as per usual, and give the links a "class" to identify them. Here, I "class"-ified them as "other_colors", and styled them to my liking. In this case, BLACK on first page-visit, PURPLE is you've been there before ("visited"), YELLOW on-hover and OLIVE on mouse-down.

    Be sure to not put a 'space' in the "class"-name. a:link.other_colors works, whilst a:link .other_colors (single space between "link" and ".other_colors")does not work... if there is a "space" in the class, ".other_links" is ignored and the 'regular' link style takes-over.

    You can create as many 'classes' for as many 'different groups of colored links' as you need.

    Be sure to keep the psuedo-class on the anchor, or else this will fail to work on IE. (That is to say, it must be a:hover where "a" is the "hyperlink" and ":hover" is the "psuedo-class"... You cannot apply ":hover" to a table cell or DIV and have it work in IE. For IE's benefit, it must be associated with an "<a href="#">foo</a>
    Last edited by WebJoel; 08-30-2006 at 07:14 PM. Reason: removed unnecessary "<pre>" tag from example

  3. #3
    Join Date
    Apr 2003
    Location
    Rosemount, MN
    Posts
    2,287
    Code:
    a.nav:link,a.nav:active,a.nav:visited{color:#FF000; font-weight:bold;}
    a.nav:hover{color:#000FF; font-weight:bold;}
    
    a.con:link,a.con:active,a.con:visited{color:#00000; font-weight:bold; text-decoration:underline;}
    a.con:hover{color:#00000; font-weight:bold;text-decoration:none;}
    HTML Code:
    <a class="nav" href="alink.com">Link nav</a>
    <a class="con" href="alink.com">Link con</a>

  4. #4
    Join Date
    Feb 2006
    Location
    Pennsylvania
    Posts
    153
    Thanks guys. Got it working.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles