1. 程式人生 > >HTML錨點定位偏移

HTML錨點定位偏移

參照 stackoverflow 的做法,在主體內容前加一個暗錨

<a class="target-fix" name="a-<?php $a->id(); ?>"></a>
<artivle>主體內容...</article>

將錨點進行偏移,並隱藏佔位:

.target-fix {
    position: relative;
    top: -44px; // 偏移值
    display: block;
    height: 0;
    overflow: hidden;
}