-3

Like on wikia, when you click on a reference number and it highlights the reference at the bottom of the page? I'm very new to coding, but I'm picking it up pretty well. Just let me know if it's possible, and give me an example please. Thanks.

Joby
  • 15
  • 1
  • 5

1 Answers1

1

Yes, there is.

There is a CSS pseudo-class...:target.

The pseudo-class :target is used to style the target element of a URI containing a fragment identifier. For example, the URI

What that means is that if you give the text (or other element) an ID (#whatever) you can specifiy what happens when that element is referenced by a click on a link that..ahem...targets that href:

#one:target {
  background: red;
}
#two:target {
  background: green;
}
#three:target {
  background: yellow;
}
.wrap div {
  width: 50px;
  height: 50px;
  display: inline-block;
  margin: 1em;
  background: #000;
}
a {
  display: inline-block;
  padding: .5em;
  background: lightgreen;
  margin: 1em;
  color: green;
  text-decoration: none;
}
<a href="#one">First</a>
<a href="#two">Second</a>
<a href="#three">Third</a>

<div class="wrap">
  <div id="one"></div>
  <div id="two"></div>
  <div id="three"></div>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
  • Do I have to make one for each and every reference though ? I have over seventy + references each page. Also it's ruining the layout every time I try to add it to my page. – Joby Feb 22 '16 at 21:38
  • Okay so I've been tweeking it a bit (as having the a element made all links on the page mint green) and I feel like I'm close to getting it right, but it's still not quite working. Any suggestions ? – Joby Feb 22 '16 at 21:58
  • Frankly what I think you are looking for is probably best handled by Javascript but without a demo it's hard to comment further. – Paulie_D Feb 22 '16 at 22:06
  • I have got the text highlighted now but the only time I want it highlighted is when the link is clicked. Is there any more help you can give for that ? – Joby Feb 22 '16 at 22:15
  • Okay I finally figured it out. I was totally skrewing up the css you gave me. Thanks. – Joby Feb 23 '16 at 00:19