2

Why doesn't code below work?

a:visited {
   background-color: yellow;
} 

taken from: http://www.w3schools.com/cssref/sel_visited.asp

What I am trying to do is have two links pointing at two different points but covering the same box. If either link is visited I want to be notified somehow. Either change background-color or border color.

example:

<a id="linkA" href="http://www.w3schools.com/">
  <a id="linkB" href ="http://www.w3schools.com/html/">
   <div id="bix">Change content if either link is visited</div>
 </a>
</a>

CSS:

#bix {
   border: 3px solid orange;
}

#linkA #bix {
   border: 3px solid green;
}

#linkB #bix {
  border: 3px solid red;
}

Problem is that when you inspect the code, #LinkA does not contain #LinkB. How can I make #LinkB inside #LinkA, or any other way to make the #bix react to visits to either #LinkA or #LinkB.

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
C3PO
  • 114
  • 1
  • 10

3 Answers3

1

Try:

a:visited + #bix { ... }

You have to change the actual content.

beautifulcoder
  • 10,832
  • 3
  • 19
  • 29
1

The correct way to create a link would be

<a href="http://www.example.com">This Will Be The Link</a>

Then when this is visited the css to change the color would be

a:visited{
    color:blue;/*will change text colour*/
    background-color:yellow;/*will change background colour*/
}

The two locations appears redundant to me as it can only go to one location?

Josh
  • 63
  • 1
  • 8
1

Nested anchor tags are forbidden in HTML syntax, hence why they're not showing up.

As @beautifulcoder suggested, change the content itself.

a:visited > #bix { color: red; }
  • And that's the problem, nested tags. I guess there is no way to fix this issue and I will have to figure out another way. – C3PO Aug 29 '14 at 21:55