Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Target goes to the top of the page

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #155921
    rodolpheb
    Participant

    Hi everyone,

    I’m struggling with the :target property in pure CSS.

    http://codepen.io/anon/pen/udGir

    When I click on the first link the anchor goes to the top which is a normal comportment.

    I’d like the content to stay still when :target is activated.

    I tried with pseudo-elements even combining them with :target but was unsuccessful.

    Thanks for your answers.

    #155976
    Merri
    Participant

    In pure CSS you can fight against it only by using some extra elements that have a fixed position: http://codepen.io/Merri/pen/cehAq

    Another alternative is JavaScript window.history.pushState but as I haven’t used it much before I didn’t get it to trigger CSS :target change, only to change the hash in the address bar.

    #155979
    rodolpheb
    Participant

    Thanks Merri, your a genius.

    I’ve already tried with fixed position but not in that way.

    #155981
    rodolpheb
    Participant

    Solved

    #156131
    noahgelman
    Participant

    Are you talking about the little bouncing the page does when you click your link?

    That only happens in codepen. It won’t jump like that on a normal web page.

    #156171
    rodolpheb
    Participant

    I don’t think so.

    I first tried on a normal web page.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘CSS’ is closed to new topics and replies.