简体   繁体   English

带有超赞字体的图标出现意外边距

[英]Unexpected margin with font-awesome icon

I have a <ul> with list-style-type:none; 我有一个<ul>具有list-style-type:none; . Instead of the list-icon I want to show a custom icon which should be variable and clickable. 我想显示一个自定义图标,而不是列表图标,该图标应该是可变的并且可以单击。 To make sure the custom icon appears to the left of the text's left margin, I added text-indent:-17px; 为了确保自定义图标出现在文本的左边距左侧,我添加了text-indent:-17px; and this works as expected. 并且这按预期工作。

However, when I have font-awesome icons in my text they seem to have their left margin (or, more like, their text-indent ) set to the indent of the containing <div>. 但是,当我的文本中有超棒的图标时,它们的左边界(或更像是他们的text-indent )似乎设置为包含<div>的缩进。 In the snapshot below the first <li> has a text-indent:-17px , the second 0px , and the third +20px . 在下面的快照中,第一个<li>具有text-indent:-17px ,第二个0px和第三个+20px

在此处输入图片说明

The first one clearly shows a negative margin-left / text-indent for the icon, while the last one has a positive margin-left. 第一个清楚地显示了该图标的负margin-left / text-indent ,而最后一个则显示了一个正的左边距。

How can I fix this, so that I can work with the negative indent? 如何解决此问题,以便可以使用否定的缩进?


The problem shows in FireFox v29, IE v11 and Chrome v35. 该问题在FireFox v29,IE v11和Chrome v35中显示。
Font-Awesome is v4.1.0 Font-Awesome是v4.1.0


My code: 我的代码:

<ul style="list-style-type:none;">
    <li>
      <div style="text-indent:-17px; margin-bottom:20px;">
        <img src="http://i.stevenvh.net/tam_none.png" alt="" /> 
        Lorem <a href="#">ipsum  <i class="fa fa-external-link"></i></a> dolor sit amet, consectetur adipiscing elit. 
      </div>
    </li>
    <li>
      <div style="text-indent:0px; margin-bottom:20px;">
        <img src="http://i.stevenvh.net/tam_none.png" alt="" /> 
        Lorem <a href="#">ipsum  <i class="fa fa-external-link"></i></a> dolor sit amet, consectetur adipiscing elit. 
      </div>
    </li>
    <li>
      <div style="text-indent:20px; margin-bottom:20px;">
        <img src="http://i.stevenvh.net/tam_none.png" alt="" /> 
        Lorem <a href="#">ipsum  <i class="fa fa-external-link"></i></a> dolor sit amet, consectetur adipiscing elit.
      </div>
    </li>
</ul>

The issue is that text-indent is inherited. 问题是text-indent是继承的。 Setting that to 20px on the third item is adding it to the inner i 将第三项设置为20px会将其添加到内部i

Doing something like this would reset the text-indent. 这样做会重置文本缩进。 Note the added style on the i 请注意i上添加的样式

http://jsfiddle.net/dJqUh/2/ http://jsfiddle.net/dJqUh/2/

<li>
  <div style="text-indent:20px; margin-bottom:20px;">
    <img src="http://i.stevenvh.net/tam_none.png" alt="" /> 
    Lorem <a href="#">ipsum  <i class="fa fa-external-link" style="text-indent:0px;"></i></a> dolor sit amet, consectetur adipiscing elit.
  </div>
</li>

It didn't do anything wrong for the second item because you set the indent to 0. It overlapps the text in the first because you have a negative indent. 对于第二个项目,它没有做错任何事情,因为您将缩进量设置为0。因为您有负的缩进,所以它与第一个文本重叠。

Working Fiddle 工作小提琴

a
{
    text-indent: 0; // inherited CSS - override it to fix the issue
}

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

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