Home > Web Front-end > CSS Tutorial > Detailed explanation of the use of CSS anchor points (newbies)

Detailed explanation of the use of CSS anchor points (newbies)

烟雨青岚
Release: 2020-07-14 12:04:47
forward
3182 people have browsed it

Detailed explanation of the use of CSS anchor points (newbies)

There are two ways to use CSS anchors. I recommend using the following:

  <a href=&#39;#one&#39;>到达第一个锚点</a>
Copy after login
Copy after login
    <a href=&#39;#two&#39;>到达第二个锚点</a>
Copy after login
Copy after login
    <p id=&#39;one&#39;>我是第一个锚点</p>
Copy after login
    <p id=&#39;two&#39;>我是第一个锚点</p>
Copy after login

In this way, when we click on the A link, the corresponding The DOM node will scroll to the top of the window.

But sometimes our need is not to let it scroll to the top of the window. You may want him to be some distance from the top. This can be solved by the following methods.

  <a href=&#39;#one&#39;>到达第一个锚点</a>
Copy after login
Copy after login
    <a href=&#39;#two&#39;>到达第二个锚点</a>
Copy after login
Copy after login
    <p id=&#39;one&#39; style=&#39;margin:top:-100px;padding-top:100px&#39;>
Copy after login
 <p >我是第一个需要滚动的内容</p>
Copy after login
   <p id=&#39;two&#39; style=&#39;margin:top:-100px;padding-top:100px&#39;>
Copy after login
    <p >我是第二个需要滚动的内容</p>
Copy after login

This will achieve the effect of 200px from the top after scrolling. Without affecting the style of the original page

Thank you everyone for reading, I hope you will benefit a lot.

This article is reproduced from: https://blog.csdn.net/baidu_32519511/article/details/52668834

Recommended tutorial: "CSS Tutorial" //m.sbmmt.com/css -tutorial.html

The above is the detailed content of Detailed explanation of the use of CSS anchor points (newbies). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template