我有一个问题,文本没有出现在圆圈的中心,我该如何解决?
#indexClient {
float: left;
margin-top: 10px;
margin-left: 20px;
width: 150px;
height: 150px;
border-radius: 50%;
font-size: 30px;
color: yellow;
line-height: 20px;
text-align: center;
background: #99CCCC
}Run Code Online (Sandbox Code Playgroud)
<div id="indexClient">
<p>Client Side</p>
</div>Run Code Online (Sandbox Code Playgroud)
Sti*_*ers 17
line-height同样的height技巧(适用于单行文本).
.circle {
width: 150px;
height: 150px;
border-radius: 50%;
font-size: 30px;
background: #9cc;
line-height: 150px;
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<div class="circle">Hello</div>Run Code Online (Sandbox Code Playgroud)
line-height+inline-block(适用于单行和多行文本).
.circle {
width: 150px;
height: 150px;
border-radius: 50%;
font-size: 30px;
background: #9cc;
line-height: 150px;
text-align: center;
}
.circle span {
display: inline-block;
vertical-align: middle;
line-height: normal;
padding: 0 25px;
}Run Code Online (Sandbox Code Playgroud)
<div class="circle">
<span>Test Long Item</span>
</div>Run Code Online (Sandbox Code Playgroud)
table+table-cell(适用于单行和多行文本).
.circle {
width: 150px;
height: 150px;
border-radius: 50%;
font-size: 30px;
background: #9cc;
text-align: center;
display: table;
}
.circle span {
display: table-cell;
vertical-align: middle;
padding: 0 25px;
}Run Code Online (Sandbox Code Playgroud)
<div class="circle">
<span>Test Long Item</span>
</div>Run Code Online (Sandbox Code Playgroud)
transform(适用于单行和多行文本).
.circle {
width: 150px;
height: 150px;
border-radius: 50%;
font-size: 30px;
background: #9cc;
text-align: center;
position: relative;
}
.circle span {
position: absolute;
left: 50%;
top: 50%;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}Run Code Online (Sandbox Code Playgroud)
<div class="circle">
<span>Test Long Item</span>
</div>Run Code Online (Sandbox Code Playgroud)