DEV Community

Discussion on: 100% Pure HTML/CSS Page Navigation - No JavaScript Required

Collapse
 
paulbrowne profile image
paulbrowne • Edited

Slightly simpler version, making use of the :not() and :target
This allows for the use of a non-hash link for the homepage.
And no need for the display:block

<style>
    section:not(:target):not(#home),
    section:target ~ #home {
        display: none
    }
</style>
<nav>
    <a href="/">home</a>
    <a href="#contact">contact</a>
    <a href="#about">about</a>
    <a href="#blog">blog</a>
</nav>
<main>
    <section id="contact">contact section...</section>
    <section id="about">about section...</section>
    <section id="blog">blog section...</section>
    <section id="home">home section...</section>
</main>
Enter fullscreen mode Exit fullscreen mode