将固定标题和侧边栏居中?
我正在尝试使用固定标题和侧边栏创建布局,但我不想将布局放在浏览器的中心。显然,这是一个问题,因为固定通常不允许这样做。我考虑过对所有内容进行包装并使用 margin: 0px auto;等等,但这不起作用,是否可能?
#header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 150px;
background-color: #FFF;
z-index: 100;
}
#content {
width: 1112px;
overflow: auto;
padding-top: 150px;
}
#sidebar {
position: fixed;
top: 0;
left: 0;
width: 275px;
height: 100%;
z-index: 100;
}
想到了这样的事情,但它不起作用:
body {
margin:0px 0px; padding:0px;
text-align:center;
}
#wrapper {
text-align: left;
margin: 0px auto;
}
divs:
<div id="wrapper">
<div id="header"></div>
<div id="content"></div>
<div id="sidebar"></div>
</div>
I am trying to create a layout using a fixed header and sidebar but I wan't to make the layout in the center of the browser.. Obvisously this is a problem as fixed usually doesn't allow this. I thought about putting a wrapper around everything and using margin: 0px auto; etc. but that didn't work, is it possible or not?
#header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 150px;
background-color: #FFF;
z-index: 100;
}
#content {
width: 1112px;
overflow: auto;
padding-top: 150px;
}
#sidebar {
position: fixed;
top: 0;
left: 0;
width: 275px;
height: 100%;
z-index: 100;
}
Had in mind something like this but it didn't work:
body {
margin:0px 0px; padding:0px;
text-align:center;
}
#wrapper {
text-align: left;
margin: 0px auto;
}
divs:
<div id="wrapper">
<div id="header"></div>
<div id="content"></div>
<div id="sidebar"></div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
CSS:
HTML:
如果我理解你的问题,我认为这是一种可能的方法。尝试一下,然后告诉我! :)
Try this:
CSS:
HTML:
If I understand your question, I think this is a possible way to do it. Try it, and tell me so! :)
不确定我是否理解正确 - 你的意思是这样的?
请注意,position:fixed 在 ie6 中不起作用。
Not sure if i get you right - you mean something like this?
Note that position:fixed does not work in ie6.