新手問題在這裏。試圖學習基礎知識。我有一個頁眉頁腳和一個容器的簡單頁面。在那個容器中,我想要一個圖像,並且我希望它居中。使用保證金: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