简体   繁体   English

当使用小字体大小时,为什么“超凡字体”图标顶部会出现奇怪的“边距”?

[英]Why Font Awesome icons have weird “margin” on top when using small font-sizes?

My goal is to align font-awesome icon with div next to it. 我的目标是将超棒字体图标与旁边的div对齐。 For some reason the font-awesome icons seem to have some margin on top of the icons on small font-sizes, which expands the wrapper div. 由于某种原因,字体超赞的图标似乎在小字体大小的图标上方有一定的空白,从而扩展了包装器div。 The same does not occur with, for example, the p tag. 例如,p标签不会发生相同的情况。 Example can be found here: 示例可以在这里找到:

https://jsfiddle.net/jaakkokarhu/Luw8dsa8/2/ https://jsfiddle.net/jaakkokarhu/Luw8dsa8/2/

Few points: 几点:

  • The margin is not either margin of the icon element or :before pseudoelement 边距既不是图标元素的边距,也不是:before伪元素前
  • It is not padding of the parent element 不是父元素的填充
  • The icon expands the parent the same amount until the font-size is 15px 图标将父级展开相同的大小,直到font-size为15px

What is causing the font-awesome icons to behave accordingly? 是什么导致超棒字体图标相应地起作用? How can I set the icon and the wrapper so that the icon is not having the top "margin"? 如何设置图标和包装,以使图标没有顶部的“边距”?

// This text is just for removing the ridiculous "links to JS fiddle needs to be accompanied by code" warning. Ignore this.

Inline-block fills in the what the browser believes is the font-size with your icon inside of it. 内联块填充了浏览器认为是带有图标的字体大小。 It does this correctly for some and for smaller icons it enters ghost space. 对于某些图标,它可以正确执行此操作,对于较小的图标,它可以进入幻像空间。 This is also noticeable if you add none breaking spaces in your HTML because they have "inline" in the css declaration and it tries to keep this with integrity. 如果您在HTML中不添加任何空格,这也是很明显的,因为空格在css声明中具有“内联”,并且它试图保持完整性。

Fix for this is either removing inline-block for the font-awesome class. 解决此问题的方法是删除font-awesome类的inline-block。 Or add font-size: 0; 或添加字体大小:0; in your wrapper class. 在包装器类中。

.wrapper {font-size: 0}

https://jsfiddle.net/Luw8dsa8/3/ https://jsfiddle.net/Luw8dsa8/3/

The gap is because of [class^="icon"] { display: inline-block; 差距是由于[class ^ =“ icon”] {display:inline-block; }. }。 It will behave same as p tag if you make it to display:block. 如果将其设置为display:block,则其行为与p标签相同。

The culprit is [class^="icon"] { display: inline-block; } 罪魁祸首是[class^="icon"] { display: inline-block; } [class^="icon"] { display: inline-block; } , though I don't know why. [class^="icon"] { display: inline-block; } ,尽管我不知道为什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM