我有一个像这样的 HTML:
<div class='number'><div class='n'><span>1</span></div></div>
现在,我想将它居中,如下图所示。我该怎么做?
Jsfiddle:link
最佳答案
这是一个 FIDDLE
.number {
background: green;
position: relative;
width: 200px;
height: 200px
}
.n {
background: red;
position: absolute;
top: 50%;
left: 50%;
margin-top: -60px;
margin-left: -60px;
width: 120px;
height: 120px;
line-height: 120px;
text-align: center;
font-size: 20px;
color: #fff;
border-radius: 100%;
}
关于html - 将 Div 水平和垂直居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23002054/