margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2328字,纯文字阅读大概需要4分钟。
内容图文
![margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose](/upload/InfoBanner/zyjiaocheng/399/e4f977a7e09a4231b7b6c6c165c5fc06.jpg)
#header {
width: 90%;
height: 50px;
background-color: orange;
overflow: auto;
position:fixed;
margin:auto;
z-index: 1;
}
图中的橙色块怎么也居中不了
我尝试过修改代码的次序,也试过不要overflow,z-index等代码,还是没有解决问题
希望各位帮忙解决一下,谢谢!
回复讨论(解决方案)
贴你完整的html和css
-------------------------------------------------------------------------------------
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;
}
贴你完整的html和css
-------------------------------------------------------------------------------------
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;
}
改成
#header {
width: 90%;
height: 50px;
background-color: orange;
overflow: auto;
margin: auto;
position: fixed;
z-index: 1;
left:0px;right:0px;
}
即可
如果完全居中,你还可以加上
html,body{text-align:center}
如果完全居中,你还可以加上
html,body{text-align:center}
确实可行,不过我想请教一下,
text-align不是对文字进行居中处理的吗?
内容总结
以上是互联网集市为您收集整理的margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose全部内容,希望文章能够帮你解决margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。