新手问题在这里。试图学习基础知识。我有一个页眉页脚和一个容器的简单页面。在那个容器中,我想要一个图像,并且我希望它居中。使用保证金:0汽车没有这样做。我曾尝试明确给容器一个宽度,但仍然不好。谢谢。图像不居中使用css
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绝对 - 你需要给它留下':50%;变换:平移X(-50%);' – Pete