问题描述
我已经开始在一个全新的网站上工作,并且一直在玩设计,但是我似乎遇到的一个问题是关于定位一个固定为滚动的全屏宽度的导航栏.下面我创建了一个名为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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)