Answer the question
In order to leave comments, you need to log in
How to cancel :target after page reload?
Hello.
When using :target, I encountered a bug:
When the :target event is fired on an element, it remains after the page is reloaded.
An example of a bug could not be implemented on a code pen or fiddle.
CSS looks like this
#el-target01:target ~ a{
color:red;
}
#el-target02:target ~ a{
color:green;
}
Answer the question
In order to leave comments, you need to log in
Most likely, when you click on a link, a fragment with a hash gets into the url. And after the reboot, this fragment remains in the url.
You can try this code on page load:
It will discard everything before # on the command line. Should work. In any case, you need to look for a solution through JS. You can dig into the History API. Here is a good article .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question