Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show section/div depends on after hash # value in link

Tags:

html

css

I have following page

section {
 height: 1000px;
 background: yellow;
 margin: 50px;
}
<section id="one">Section one</section>
<section id="two">Section two</section>

It is possible using html/css only to show only ONE section if user came from link which contains section id after hash e.g

  • if user go to link http://my-site/page#one he should only see section one
  • if user go to link http://my-site/page#two he should only see section two
  • if user go to link http://my-site/page he should see all sections

?

like image 573
Kamil Kiełczewski Avatar asked Dec 24 '22 01:12

Kamil Kiełczewski


1 Answers

You can investigate the use of the :target pseudo-class, but you might struggle to show all of the sections when the URL hash is empty.

For example:

section:not(:target) { display:none; }
section:target { display: block }
<a href="#one">One</a>
<a href="#two">Two</a>

<section id="one">Section one</section>
<section id="two">Section two</section>
like image 115
BenM Avatar answered Jan 05 '23 00:01

BenM