Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda