我有一个父节内的几个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