最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose

来源:动视网 责编:小采 时间:2020-11-27 15:53:14
文档

margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose

margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose:这是我的CSS代码 #header { width: 90%; height: 50px; background-color: orange; overflow: auto; position:fixed; margin:auto; z-index: 1; } 图中的橙色块怎么也居中不了 我尝试过修改代码的次序,也试过不要ove
推荐度:
导读margin:auto和position:fixed不能同时使用么_html/css_WEB-ITnose:这是我的CSS代码 #header { width: 90%; height: 50px; background-color: orange; overflow: auto; position:fixed; margin:auto; z-index: 1; } 图中的橙色块怎么也居中不了 我尝试过修改代码的次序,也试过不要ove


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

图中的橙色块怎么也居中不了
我尝试过修改代码的次序,也试过不要overflow,z-index等代码,还是没有解决问题
希望各位帮忙解决一下,谢谢!


回复讨论(解决方案)

贴你完整的html和css




First 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;
}

贴你完整的html和css





First 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;
}

改成
#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:这是我的CSS代码 #header { width: 90%; height: 50px; background-color: orange; overflow: auto; position:fixed; margin:auto; z-index: 1; } 图中的橙色块怎么也居中不了 我尝试过修改代码的次序,也试过不要ove
推荐度:
标签: html css auto
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top