1
鑑於<div id='pageheader'>
,用下面的CSS:防止固定頭從隱藏的文本與CSS
#pageheader { position: fixed; top: 0px; width: 100%; height: 35px; }
body { margin-top: 35px; }
我有保持固定在頁面頂部的標題。問題是當用戶點擊鏈接到同一頁面的另一部分時,該鏈接的目標出現在的的標題下。我不知道如何防止這種情況。
編輯:我結束了使用jQuery給內部鏈接一個平滑的滾動,從而消除了這個問題。
$("span.sect1, span.sect2").click(function(){
var target = '#' + $(this).find("a").attr('href').match(/#(.*)$/)[1];
var position = $(target).offset();
$('html, body').animate({scrollTop: (position.top -40)}, "slow");
});
$("a.xref").click(function(){
var target = '#' + $(this).attr('href').match(/#(.*)$/)[1];
var position = $(target).offset();
$('html, body').animate({scrollTop: (position.top -40)}, "slow");
});
不幸的是,我需要通過使用CSS有效的解決方案。 HTML是從docbook XML生成的,鏈接是標識符,而不是隱藏的錨。 – Scribblemacher 2012-04-06 13:49:39
那麼,你可以將CSS應用到'h1':'position:relative;頂部:-35px; padding-top:35px;' – 2012-04-06 13:50:53
雖然有效,但該技術也會更改頁面佈局的其他部分。例如,某些標題具有背景顏色並跨越頁面,並且像這樣更改它們的填充會增加它們的可見高度。我也很難預測頁面上可能成爲鏈接目標的所有對象。 – Scribblemacher 2012-04-06 14:26:28