ola*_*ndo 24 html anchor center
我在html页面上有一个锚点的链接.单击链接时,会导致页面滚动到锚点,以使锚点位于页面可见部分的最顶部.如何使页面滚动以使锚点位于页面中间?
cha*_*hsu 14
我找到了一个解决方案Anchor Links With A Fixed Header由Phillip发布,他是一名网页设计师.Phillip添加了一个新的EMPTY跨度作为锚定位置.
<span class="anchor" id="section1"></span>
<div class="section"></div>
Run Code Online (Sandbox Code Playgroud)
然后把下面的css代码
.anchor{
display: block;
height: 115px; /*same height as header*/
margin-top: -115px; /*same height as header*/
visibility: hidden;
}
Run Code Online (Sandbox Code Playgroud)
谢谢,菲利普!
小智 10
HTML:
<a id="anchor">NEWS</a>
Run Code Online (Sandbox Code Playgroud)
CSS:
#anchor{
position: relative;
padding-top: 100px; //(whatever distance from the top of the page you want)
}
Run Code Online (Sandbox Code Playgroud)
对我来说很好
小智 7
放置一个<span class="anchor" id="X">然后设置样式的anchor类,如:
.anchor {
position: absolute;
transform: translateY(-50vh);
}
Run Code Online (Sandbox Code Playgroud)
随着-50vh锚将在屏幕中间滚动。
| 归档时间: |
|
| 查看次数: |
36480 次 |
| 最近记录: |