我有一個父節內的幾個div,我試圖做一個對齊,使div在節中居中。就像他們現在一樣,divs是左對齊的。我試過做margin: 0 auto
但這不起作用。任何人都可以解釋我怎麼能做到這一點?水平對齊父節內的多個div
section {
margin-bottom: 10px;
width: 100vw;
height: 100vh;
}
.notice {
width: 50vw;
height: 10vh;
}
section .socialmedia{
background-color: red;
width: 100vw;
height: 15vh;
}
//The divs I'm trying to center
section .icon{
margin: 0 auto;
width: 15vw;
height: 15vh;
background-color: green;
}
<section>
<div class="notice">
<h1>Our website is currently undergoing construction, please feel free to contact us on social media.</h1>
</div>
<div class="socialmedia">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
</section>
謝謝,我已更新我的代碼以顯示您所建議的更改並且它不起作用。 – Robert
適用於我:https://codepen.io/anon/pen/jBRjYW(順便說一句,// CSS中的註釋無效,請參閱鏈接的筆)。 – vbulant
這可能是因爲我嘗試過的評論或我的緩存。感謝您的幫助。 – Robert