Home > Web Front-end > CSS Tutorial > Do you know how to use css anchors?

Do you know how to use css anchors?

王林
Release: 2020-09-15 17:36:27
forward
2434 people have browsed it

Do you know how to use css anchors?

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

(Recommended tutorial: CSS tutorial)

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

So when we click on link A, the corresponding 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>
    <a href=&#39;#two&#39;>到达第二个锚点</a>
    <div id=&#39;one&#39; style=&#39;margin:top:-100px;padding-top:100px&#39;>
    <div >我是第一个需要滚动的内容</div>
   <div id=&#39;two&#39; style=&#39;margin:top:-100px;padding-top:100px&#39;>
    <div >我是第二个需要滚动的内容</div>
Copy after login

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

The above is the detailed content of Do you know how to use css anchors?. 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