0

Is there a way for CSS to change its properties if there's a value after a "#" in the URL? For example, if I click a link which turns my page from /book.php to /book.php#read, is there a way to make a CSS DIV become visible?

I can probably accomplish this with JavaScript (though it will be a slight pain) but I'm wondering if there's a CSS method which can do this?

Thanks!

Brendan
  • 107
  • 2
  • 13

1 Answers1

1

If I have understood the question correctly, it is possible to do this with css only using the :target pseudo-class from CSS.

Here is an example of how it works:

:target{
        display: none;
    }
<a href="#content1">Hide Content 1</a>
<a href="#content2">Hide Content 2</a>

<p id="content1">Content 1</p>
<p id="content2">Content 2</p>

you can learn more here:

w3schools

developer.mozilla

Richard Parnaby-King
  • 14,703
  • 11
  • 69
  • 129
Iury Piva
  • 35
  • 10