How to Create Space Above an Anchor Link?

Patricia Arquette
Release: 2024-11-06 08:21:02
Original
967 people have browsed it

How to Create Space Above an Anchor Link?

Adjusting Anchor Link Position on Page

When accessing a page section via an anchor link, users typically expect it to bring them to the linked area at the top of the page. However, in certain scenarios, it may be desirable to maintain some vertical space above the linked element.

To achieve this, the solution lies in the scroll-margin-top property, which specifies the amount of space (in pixels) that should be maintained between the linked element and the top of the page after the anchor link is clicked.

Example code:

<code class="css">#anchor {
  scroll-margin-top: 100px;
}</code>
Copy after login

In this example, the #anchor element will be positioned 100 pixels below the top of the page after the corresponding anchor link is activated.

It's important to note that the scroll-margin-top property is supported across modern browsers, ensuring reliable behavior on various platforms.

The above is the detailed content of How to Create Space Above an Anchor Link?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!