定位“包装器"固定导航栏下的div?

Positioning a quot;wrapperquot; div underneath a fixed navigation bar?(定位“包装器固定导航栏下的div?)

本文介绍了定位“包装器"固定导航栏下的div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始在一个全新的网站上工作,并且一直在玩设计,但是我似乎遇到的一个问题是关于定位一个固定为滚动的全屏宽度的导航栏.下面我创建了一个名为wrapper"的 div,它被设置为以 980px 的宽度居中.下面是代码示例;

I've started work on a brand new site and i've been playing around with designs for a while, however one problem I seem to be having is regarding positioning a navigation bar with a full screen width that is fixed to scroll. Underneath i have created a div called "wrapper" which is set to centre at a width of 980px. Below is code example;

<style>
    #navBar {
        background: RGB(0, 0, 0);
        height: 30px;
        position: fixed;
        width: 100%;
    }

    #wrapper {
        margin: 0 auto;
        width: 980px;
    }
</style>

<div id="navBar">

</div>

<div id="wrapper">
    <div style="border: 1px solid RGB(0, 0, 0); float: left; height: 500px; margin: 5px; width: 400px;"></div>
</div>

我在包装器"中创建的框应该(显然不是因为我做错了什么——某处)位于 navBar 下方的 5px,但是因为我已使用 position: fixed 它位于其下方.任何人都可以指导我如何解决这个问题并让包装器直接位于导航栏下方而不是导航栏下方,同时保持其居中?

The box i created within "wrapper" SHOULD (obviously isn't because i'm doing something wrong - somewhere) sit 5px below the navBar, however because I have used position: fixed it sits underneath it instead. Could anybody lead me to how I solve this issue and have it so that the wrapper sits directly below rather than underneath the navbar whilst maintaining it's centering?

推荐答案

navbar 上设置 top:0 并在 wrapper 上添加 30px margin-top 分区

set top:0 on your navbar and add 30px margin-top on your wrapper div

#navBar {
    background: RGB(0, 0, 0);
    height: 30px;
    position: fixed;
    width: 100%;
    top:0
}
#wrapper {
    margin: 30px auto 0;
    width: 980px;
}

http://jsfiddle.net/duncan/NkRxQ/

这篇关于定位“包装器"固定导航栏下的div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:定位“包装器"固定导航栏下的div?

基础教程推荐