P粉2855875902023-08-22 17:09:27
If you can't or don't want to set a new class, you can add a fixed-height :target# to the
::before pseudo-element in CSS.
##Pseudo class:
:target::before { content: ""; display: block; height: 60px; /* 固定的标题高度 */ margin: -60px 0 0; /* 负的固定标题高度 */ }Or use jQuery to scroll the page relative to
:target:
var offset = $(':target').offset(); var scrollto = offset.top - 60; // 减去固定的标题高度 $('html, body').animate({scrollTop:scrollto}, 0);
P粉9869374572023-08-22 09:39:10
I encountered the same problem. I solved this problem by adding a class to the anchor element and using the topbar's height as the value of padding-top.
<h1><a class="anchor" name="barlink">Bar</a></h1>
I used the following CSS:
.anchor { padding-top: 90px; }