How to vertically align text with icon font?

前端 未结 10 1384
醉话见心
醉话见心 2020-11-29 01:08

I have a very basic HTML which mix plain text and icon fonts. The problem is that icons are not exactly rendered at the same height than the text:

10条回答
  •  广开言路
    2020-11-29 01:33

    To expand on Marian Udrea's answer: In my scenario, I was trying to align the text with a material icon. There's something weird about material icons that prevented it from being aligned. None of the answers were working, until I added the vertical-align to the icon element, instead of the parent element.

    So, if the icon is 24px in height:

    .parent {
        line-height: 24px; // Same as icon height
    
        i.material-icons {  // Only if you're using material icons
          display: inline-flex;
          vertical-align: top;
        }
    }
    

提交回复
热议问题