【问题标题】:How to round font-awesome icons?如何舍入字体真棒图标?
【发布时间】:2017-04-14 11:15:09
【问题描述】:

我正在尝试舍入字体真棒图标。请参考-http://jsfiddle.net/JfGVE/1704/

问题是,无论如何,圆形图标更椭圆。无法使其完美圆润。下面是我的css代码-

i {
display: inline-block;
background: gray;
color: white;
border-radius: 50%;
padding: 5px;
}

【问题讨论】:

    标签: css icons font-awesome rounded-corners


    【解决方案1】:

    最好避免以像素为单位设置固定的宽度和高度。这是使用带有after 伪元素的额外div 来绘制圆的解决方案,请参阅DEMO

    HTML:

    <div class="container">
      <i class="fa fa-close"></i>
    </div>
    

    CSS:

    .container {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      background-color: #555;
      min-width: 2em;
      border-radius: 50%;
      vertical-align: middle;
    }
    
    .container:after {
      content:'';
      float: left;
      width: auto;
      padding-bottom: 100%;
    }
    

    【讨论】:

      【解决方案2】:

      尝试调整高度/宽度并重置行高:

      i {
        display: inline-block;
        background: gray;
        color: white;
        border-radius: 50%;
        padding: 0.3em; /* adjust padding */
        line-height: initial !important; /* reset line-height */
        height: 1em;
        width: 1em;
        text-align:center;
      }
      <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
      <i class="fa fa-close"></i>
      <br>
      <i class="fa fa-camera-retro fa-lg"></i> fa-lg
      <i class="fa fa-camera-retro fa-2x"></i> fa-2x
      <i class="fa fa-close fa-3x"></i> fa-3x
      <i class="fa fa-info fa-4x"></i> fa-4x
      <i class="fa fa-camera-retro fa-5x"></i> fa-5x

      [编辑]图标大小不等于高度/宽度。 于是我改了答案,加了height: 1em; width: 1em; text-align: center;

      【讨论】:

        【解决方案3】:

        就用这个吧:

        <i class="fa fa-times-circle"></i>
        

        或者如果你愿意,你也可以试试这个:

        i.custom {
          display: inline-block;
          background: gray;
          color: white;
          border-radius: 50%;
        }
        i.custom:before,
        i.custom:after {
          display: inline-block;
          vertical-align: middle;
          height: 40px;
          width: 40px;
          line-height: 40px;
          text-align: center;
        }
        <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
        <i class="custom fa fa-close"></i>
        <i class="fa fa-times-circle"></i>

        【讨论】:

          猜你喜欢
          • 2014-01-16
          • 2012-07-31
          • 1970-01-01
          • 1970-01-01
          • 2013-12-07
          • 2017-05-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多