Would it be possible to make text become highlighted after linking to it?

Viewed 38

I don't think I really explained that well in the title so I'll try describe a bit more. Currently I am using <a id="x"> and <a href="#x"> in order to link parts of a page to a table of contents. I would like to be able to have the linked text become highlighted after clicking on its link(does that sound right?) so that its a bit more clear which part you read.

2 Answers

For links like anchors, you can use the pseudo-class :target.

:target {
    background-color: green;
    color: white;
}
<a href="#id1">one</a>
<a href="#id2">two</a>
<a href="#id3">three</a>

<div id="id1">one text</div>
<div id="id2">two text</div>
<div id="id3">three text</div>

I guess this is what you want.

:target {
    background-color: blue;
    color: white;
}
<a href="#heading"><div id="heading">HEADING</div>
</a>
<a href="#subheading1"><div id="subheading1">SubHeading 1</div>
</a>
<a href="#subheading2"><div id="subheading2">SubHeading 2</div></a>

Related