【发布时间】:2017-07-17 22:09:51
【问题描述】:
这里是新手问题。努力学习基础知识。我有一个带有页眉、页脚和容器的简单页面。在那个容器中,我想要一个图像,并且我希望它居中。使用 margin: 0 auto 没有这样做。我试过明确地给容器一个宽度,但还是不行。谢谢。
html,
body {
margin: 0px;
padding: 0px;
height: 100vh;
}
#header {
position: relative;
height: 10%;
width: 100%;
background-color: yellow;
}
#footer {
position: relative;
height: 10%;
width: 100%;
background-color: lightgray;
}
#container {
height: 80%;
width: 100vw;
background-color: red;
}
#imagewrap {
position: absolute;
border: 1px solid #818181;
z-index: 2;
height: 75%;
display: block;
margin: 0 auto;
}
<div id="header"> </div>
<div id="container">
<div id="imagewrap">
<img src="Images/01Folder/Image.jpg" height="100%" id="front" />
</div>
</div>
<div id="footer"> </div>
【问题讨论】:
-
这是因为你已经完全放置了你的 imagewrap - 你需要给它
left:50%; transform:translateX(-50%);