margin:auto 和 position:fixed不能同时使用么

hear_windows 2014-05-15 07:24:17
这是我的CSS代码
#header {
width: 90%;
height: 50px;
background-color: orange;
overflow: auto;
position:fixed;
margin:auto;
z-index: 1;
}

图中的橙色块怎么也居中不了
我尝试过修改代码的次序,也试过不要overflow,z-index等代码,还是没有解决问题
希望各位帮忙解决一下,谢谢!
...全文
516 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hear_windows 2014-05-15
  • 打赏
  • 举报
回复
引用 5 楼 net_lover 的回复:
如果完全居中,你还可以加上 html,body{text-align:center}
确实可行,不过我想请教一下, text-align不是对文字进行居中处理的吗?
孟子E章 2014-05-15
  • 打赏
  • 举报
回复
如果完全居中,你还可以加上 html,body{text-align:center}
孟子E章 2014-05-15
  • 打赏
  • 举报
回复
改成 #header { width: 90%; height: 50px; background-color: orange; overflow: auto; margin: auto; position: fixed; z-index: 1; left:0px;right:0px; } 即可
hear_windows 2014-05-15
  • 打赏
  • 举报
回复
引用 1 楼 net_lover 的回复:
贴你完整的html和css
<!DOCTYPE html> <html> <head> <title>First html</title> <link type="text/css" rel="stylesheet" href="css.css"> <head> <body> <div id="header"></div> <div class="left"></div> <div class="right"></div> <div id="footer"></div> </body> </html> ------------------------------------------------------------------------------------- div { border-radius: 5px; } #header { width: 90%; height: 50px; background-color: orange; overflow: auto; margin: auto; position: fixed; z-index: 1; } .left { width: 25%; height: 360px; background-color: gold; margin-top: 70px; margin-left: 5%; position: relative; display: inline-block; } .right { width: 60%; height: 360px; background-color: #A9A9A9; margin-top: 70px; margin-right: 5%; position: relative; display: inline-block; } #footer { width: 90%; height: 50px; background-color: #00FF00; margin: auto; margin-top: 20px; position: relative; clear: both; }
hear_windows 2014-05-15
  • 打赏
  • 举报
回复
<!DOCTYPE html> <html> <head> <title>First html</title> <link type="text/css" rel="stylesheet" href="css.css"> <head> <body> <div id="header"></div> <div class="left"></div> <div class="right"></div> <div id="footer"></div> </body> </html> ------------------------------------------------------------------------------------- div { border-radius: 5px; } #header { width: 90%; height: 50px; background-color: orange; overflow: auto; margin: auto; position: fixed; z-index: 1; } .left { width: 25%; height: 360px; background-color: gold; margin-top: 70px; margin-left: 5%; position: relative; display: inline-block; } .right { width: 60%; height: 360px; background-color: #A9A9A9; margin-top: 70px; margin-right: 5%; position: relative; display: inline-block; } #footer { width: 90%; height: 50px; background-color: #00FF00; margin: auto; margin-top: 20px; position: relative; clear: both; }
孟子E章 2014-05-15
  • 打赏
  • 举报
回复
贴你完整的html和css
Re: 《文件备份与压缩命令》 ---------------------------------------内容提要: 1/6)tar   命令:打包备份/解压打包(将文件或目录的压缩或不解压查看查看)2/6)gzip  命令:压缩或解压文件3/6)zip   命令:打包和压缩文件4/6)unzip 命令:解压zip文件5/6)scp   命令:远程文件复制(全量备份)6/6)rsync 命令:文件同步工具(增量备份)  本人在教学和实战过程中发现,即便是有一定运维经验的人,可能已经能够搭建一定复杂度的Linux架构,但是在来来回回的具体操作中,还是体现出CLI(命令界面)功底不够扎实,甚至操作的非常‘拙’、处处露‘怯’。 对一个士兵来说,枪就是他的武器,对于一个程序员来说,各种library(工具库)就是他的武器;而对于Linux运维人员来说,无疑命令行工具CLI(命令界面)就是他们的武器;高手和小白之间的差距往往就体现在对于这些“武器”的掌握和熟练程度上。有时候一个参数就能够解决的事情,小白们可能要写一个复杂的Shell脚本才能搞定,这就是对CLI(命令界面)没有理解参悟透彻导致。 研磨每一个命令就是擦拭手中的作战武器,平时不保养不理解,等到作战的时候,一定不能够将手中的武器发挥到最好,所以我们要平心、静气和专注,甘坐冷板凳一段时间,才能练就一身非凡的内功! 本教程从实战出发,结合当下流行或最新的Linux(v6/7/8 版本)同时演示,将命令行结合到解决企业实战问题中来,体现出教学注重实战的务实精神,希望从事或未来从事运维的同学,能够认真仔细的学完Linux核心命令的整套课程。 本课程系列将逐步推出,看看我教学的进度和您学习的步伐,孰占鳌头! 注:关于教学环境搭建,可以参考本人其它课程系列,本教学中就不再赘述! 《参透 VMware 桌面级虚拟化》 《在虚拟机中安装模版机(包括应用软件等)》 《SecureCRT 连接 GNS3/Linux 的安全精密工具》

61,111

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧