【发布时间】:2017-10-27 14:31:03
【问题描述】:
我有一个固定的标题,因为它是固定的它吃一些页面,所以我需要在first-page-content 中添加一个margin-top。我考虑过使用一个 jQuery 脚本来检查header 呈现的height 并将其作为margin-top 添加到first-page-content。它可以工作,但有时我需要刷新页面,这对用户来说相当麻烦。
脚本(在页脚处):
$(document).ready(function(){ // This function is activated after the document is loaded
$('.first-page-content').css('margin-top', $('#header').height()); // Sets the margin-top of the first-page-content as the height of the header
});
In case you need the jQuery API documentation
编辑:当它不起作用时,标题吃一些.first-page-content,因为没有margin-top。
【问题讨论】:
-
首先,如果脚本在页脚中,则不需要准备好文档。其次,您没有说明“为什么”必须刷新。实际问题是什么。
-
@Taplar,谢谢,我会删除
$(document).ready():]