Smooth scroll to top of page with CSS/HTML only?

前端 未结 3 1271
伪装坚强ぢ
伪装坚强ぢ 2021-02-13 05:46

I am not permitted to add in Jquery/Javascript to this site, so I was looking for any way to do a \"Back to Top\" button, and have it transition to top with CSS/HTML only....don

3条回答
  •  深忆病人
    2021-02-13 06:28

    As far as I am aware of, there is no way to do a smooth page transition using only CSS. As aaronman stated, you can use the HTML attribute of id to help jump to different places on the page. You give the element the id, which can be whatever you want

    Jump to me

    Then somewhere on the page, you can use an anchor tag to be able to jump to this.

    Jump to "Jump to me"
    

    Fiddle

    The way this works is very similar to targeting an element in CSS. You target it using the id, and the href will take you there. This is helpful for projects such as table of contents. In the case you are making something such as a table of contents and you want to show that you have jumped to a section, you can use the :target pseudo class to accomplish this. Here is a very basic example.

    The way you can do this without having an element to jump to is by giving the a an href of #. This will jump straight to the top of the page. It is almost like the of the page has an id of #.

    Fiddle

提交回复
热议问题