0

I am having trouble creating a link (a href) where certain characters show up in different colors but function as one link!

I tried to think creative and came up with the following codes.

HTML:

<a href="#" class="char1"> T </a>
<a href="#" class="char2"> E </a>
<a href="#" class="char3"> S </a>
<a href="#" class="char4"> T </a>


CSS:

a.char1:link {color:#fff; font-size:13pt; text-decoration:none;}
a.char1:visited {color:#fff; font-size:13pt; text-decoration:none;}
a.char1:active {color:#fff; font-size:13pt; text-decoration:none;}
a.char1:hover {color:blue; font-size:13pt; text-decoration:none;}

a.char2:link {color:#fff; font-size:13pt; text-decoration:none;}
a.char2:visited {color:#fff; font-size:13pt; text-decoration:none;}
a.char2:active {color:#fff; font-size:13pt; text-decoration:none;}
a.char2:hover {color:red; font-size:13pt; text-decoration:none;}

a.char3:link {color:#fff; font-size:13pt; text-decoration:none;}
a.char3:visited {color:#fff; font-size:13pt; text-decoration:none;}
a.char3:active {color:#fff; font-size:13pt; text-decoration:none;}
a.char3:link {color:green; font-size:13pt; text-decoration:none;}

a.char4:link {color:#fff; font-size:13pt; text-decoration:none;}
a.char4:visited {color:#fff; font-size:13pt; text-decoration:none;}
a.char4:active {color:#fff; font-size:13pt; text-decoration:none;}
a.char4:hover {color:yellow; font-size:13pt; text-decoration:none;}

But then of course they won't function as a single link...

So again to simplify my question I want to create a href where all 'four' characters (T, E, S, T) show in diffrent colors when being hovered (a.char:hover).

"despite the fact only one character is hovered in this case"


thanks in advance!

3
  • 1
    Use a single link which contains multiple span elements each with a separate character / styles Commented Feb 17, 2015 at 19:44
  • You could put each letter in a span like this codepen.io/anon/pen/azYdoE Commented Feb 17, 2015 at 19:44
  • you can have random colors too using some JS code -- stackoverflow.com/questions/20228961/… Commented Feb 17, 2015 at 19:56

2 Answers 2

1

Like so--put the text into spans within the anchor tag:

 body {
   background-color: #656565;
 }
 a:link .char1 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:visited .char1 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:active .char1 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:hover .char1 {
   color: blue;
   font-size: 13pt;
   text-decoration: none;
 }
 a:link .char2 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:visited .char2 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:active .char2 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:hover .char2 {
   color: red;
   font-size: 13pt;
   text-decoration: none;
 }
 a:link .char3 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:visited .char3 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:active .char3 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:link .char3 {
   color: green;
   font-size: 13pt;
   text-decoration: none;
 }
 a:link .char4 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:visited .char4 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:active .char4 {
   color: #fff;
   font-size: 13pt;
   text-decoration: none;
 }
 a:hover .char4 {
   color: yellow;
   font-size: 13pt;
   text-decoration: none;
 }
<a href="#">
  <span class="char1">T</span>
  <span class="char2">E</span>
  <span class="char3">S</span>
  <span class="char4">T</span>
</a>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick reply helped me allot!
0

you have to give hover for char 3 also.

HTML:

 <a href="#">
<span class="char1">T</span>
<span class="char2">E</span>
<span class="char3">S</span>
<span class="char4">T</span>
</a>

CSS:

a:link  .char1 .char2 .char3 .char4
{color:#fff; font-size:13pt; text-decoration:none;}

a:visited .char1 .char2 .char3 .char4
{color:#fff; font-size:13pt; text-decoration:none;}

a:active .char1 .char2 .char3 .char4
{color:#fff; font-size:13pt; text-decoration:none;}

a:hover .char1 {color:blue; font-size:13pt; text-decoration:none;}
a:hover .char2 {color:red; font-size:13pt; text-decoration:none;}
a:hover  .char3{color:green; font-size:13pt; text-decoration:none;}
a:hover  .char4{color:yellow; font-size:13pt; text-decoration:none;}

1 Comment

Thanks for the quick reply helped me allot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.