2017-05-02 19 views
0

我用下面的代碼:如何使fontawesome圖標到其父的中心

<div style="width:60px; height:60px; background-color: lightgrey;"> 
    <a class="" href="javascript:void(0)" style="color: black; width: inherit; height: inherit;"> 
    <i class="fa fa-lg fa-play" aria-hidden="true" style="width: inherit; height: inherit;"></i> 
    </a> 
</div> 

,我得到以下幾點:

enter image description here

如何使播放圖標爲灰色塊中心?

+0

[CSS中心文本(水平和垂直)一個DIV塊內(的可能的複製http://stackoverflow.com/questions/5703552/css-center-text-horizo​​ntal-和垂直內-A-DIV塊) –

回答

0

您需要將i元件的text-align屬性設置爲text-align: center;並且然後該容器設置爲line-height: 60px;行=高度應與外容器的高度。

i { 
 
    text-align: center; 
 
} 
 
a { 
 
    line-height: 60px; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> 
 
<div style="width:60px; height:60px; background-color: lightgrey;"> 
 
    <a class="" href="javascript:void(0)" style="color: black; width: inherit; height: inherit;"> 
 
    <i class="fa fa-lg fa-play" aria-hidden="true" style="width: inherit; height: inherit;"></i> 
 
    </a> 
 
</div>