【发布时间】:2017-06-08 21:29:29
【问题描述】:
我正在尝试将页面上的一些元素垂直和水平居中,但由于某种原因,将容器元素设置为具有 auto 边距不会使它们居中。谁能解释一下为什么?
HTML/CSS
body{
margin: 0;
padding: 0;
background-color: rgb(0, 0, 0);
}
#links{
margin: auto;
}
.link{
display: inline-block;
margin: 0 2%;
width: 15vw;
height: 15vw;
border: 2px solid rgb(100, 100, 0);
border-radius: 50%;
background-image: url("line.png");
background-repeat: no-repeat;
background-size: contain;
background-position: center;
background-color: rgb(0, 0, 50);
}
.link:first-of-type{
margin-left: 0;
}
.link:last-of-type{
margin-right: 0;
}
<div id="landingpage">
<section id="links">
<div class="link" id="home"></div>
<div class="link" id="work"></div>
<div class="link" id="contact"></div>
</section>
</div>
【问题讨论】: