How to position text over Font Awesome icon?

喜夏-厌秋 提交于 2020-01-13 15:53:29

问题


Is there a way to vertically align text stacked on top of a Font Awesome icon? I'd like to move the #1 up in this stack so that it is centered in the cup of the trophy icon. I tried adding bottom-margin and bottom-padding in the span that encapsulates the #1, but neither one did the trick. Is there an easy way to do what I'm trying to accomplish, or do I need to go another route?

<span class="fa-stack fa-3x">
  <i class="fa fa-trophy fa-stack-2x"></i>
  <span class="fa fa-stack-1x" style="color:red;">
    <span style="font-size:35px;">
      #1
    </span>
  </span>
</span> 

http://jsfiddle.net/wc2jP/


回答1:


Add display:block; margin-top:-20px; to the #1 <span> tag like so:

http://jsfiddle.net/wc2jP/1/




回答2:


A couple of months after you asked this question, the team at Font Awesome blogged about this with examples using their calendar, comment, and file icons: Stacking Text and Icons




回答3:


you can use line-height property as well with display:inline-block.

span{
vertical-align:top; 
display:inline-block; 
line-height:1.6em;
}

Here is the Working Demo.



来源:https://stackoverflow.com/questions/22644741/how-to-position-text-over-font-awesome-icon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!