Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
How to avoid jumping when click on anchor link

I want to show/hide content using purely CSS without JavaScript. I reached on this solution.

When I click on the link it jump down in page. I need pure CSS solution, how to stop it to jump?

p[id^="detailView-"] {
  display: none;
}

p[id^="detailView-"]:target {
  display: block;
}
<a href="#detailView-1">Show View1</a>
<p id="detailView-1">View1</p>

<a href="#detailView-2">Show View2</a>
<p id="detailView-2">View2</p>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Just arrange your html so the anchor tags are at the top like so

p[id^="detailView-"] {
  display: none;
}

p[id^="detailView-"]:target {
  display: block;
}
<a href="#detailView-1">Show View1</a>
<a href="#detailView-2">Show View2</a>

<p id="detailView-1">View1</p>
<p id="detailView-2">View2</p>

about 4 years ago · Juan Pablo Isaza Report

0

In this situation, instead of toggling between:

  • display: none
  • display: block

you can toggle between:

  • visibility: hidden
  • visibility: visible

The difference betwen the two properties is that:

  • visibility maintains page-space for an element, even when that element is invisible
  • display: none will actually remove the element from the page and collapse the space that it was occupying

Working Example:

p[id^="detailView-"] {
  visibility: hidden;
}

p[id^="detailView-"]:target {
  visibility: visible;
}
<a href="#detailView-1">Show View1</a>
<p id="detailView-1">View1</p>

<a href="#detailView-2">Show View2</a>
<p id="detailView-2">View2</p>


Further Reading:

  • https://developer.mozilla.org/en-US/docs/Web/CSS/visibility
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!