0

我有一个使用 html5 的导航和标题。导航固定在页面顶部。它的高度没有在 css 中明确定义(它通过字体大小、填充等创建)。

我在导航下方添加了一个标题。我需要找到一种在页眉顶部添加边距的方法,以使页眉 100% 位于导航下方(没有遮盖,没有磨合)。添加导航的高度作为边距可以做到这一点,但除此之外,我需要将导航的高度添加(添加)到已经在 css 中定义的边距。我使用此代码无济于事。

*#main=导航

<script>
$(document).ready(function(){
$("header").css("margin-top", parseInt($(this)[0].css("margin-top") + $("#main")[0].outerHeight) + "px");
});
</script>

请帮忙!

4

1 回答 1

2

I got it. I used an iteration of ilya's idea. I added a container around everything that wasn't the nav and added top padding that was the height of the nav. I of course accomplished this through jQuery:

$("#container").css("padding-top", $("#main").outerHeight() + "px" );

It works wonderfully. Thank you!

于 2013-07-31T22:01:41.817 回答