Make Font Awesome icons in a circle?

前端 未结 14 1107
情书的邮戳
情书的邮戳 2020-12-02 04:38

I am using font awesome on some project but I have some things that I want to do with font awesome icons, I can easily call an icon like this:



        
相关标签:
14条回答
  • 2020-12-02 05:18

    You can simply get round icon using this code:

    <a class="facebook-share-button social-icons" href="#" target="_blank">
        <i class="fab fa-facebook socialicons"></i>
    </a>
    

    Now your CSS will be:

    .social-icons {
    display: inline-block;border-radius: 25px;box-shadow: 0px 0px 2px #888;
    padding: 0.5em;
    background: #0D47A1;
    font-size: 20px;
    }
    .socialicons{color: white;}
    
    0 讨论(0)
  • 2020-12-02 05:27

    With Font Awesome you can easily use stacked icons like this:

    <span class="fa-stack fa-2x">
      <i class="fas fa-circle-thin fa-stack-2x"></i>
      <i class="fas fa-lock fa-stack-1x fa-inverse"></i>
    </span>
    

    refer Font Awesome Stacked Icons

    Update:- Fiddle for stacked icons

    0 讨论(0)
  • 2020-12-02 05:27

    Font icon in a circle using em as the base measurement

    if you use ems for the measurements, including line-height, font-size and border-radius, with text-align: center it makes things pretty solid:

    #info i {
      font-size: 1.6em;
      width: 1.6em;
      text-align: center;
      line-height: 1.6em;
      background: #666;
      color: #fff;
      border-radius: 0.8em; /* or 50% width & line-height */
    }
    
    0 讨论(0)
  • 2020-12-02 05:27

    UPDATE:

    Upon learning flex recently, there is a cleaner way (no tables and less css). Set the wrapper as display: flex; and to center it's children give it the properties align-items: center; for (vertical) and justify-content: center; (horizontal) centering.

    See this updated JS Fiddle


    Strange that nobody suggested this before.. I always use tables to do this.
    Simply make a wrapper have display: table and center stuff inside it with text-align: center for horizontal and vertical-align: middle for vertical alignment.

    <div class='wrapper'>
      <i class='icon fa fa-bars'></i>
    </div>
    

    and some sass like this

    .wrapper{
      display: table; 
    
      i{
        display: table-cell;
        vertical-align: middle;
        text-align: center;
      }
    
    }
    

    or see this JS Fiddle

    0 讨论(0)
  • 2020-12-02 05:29

    Update: Rather use flex.

    If you want precision this is the way to go.

    Fiddle. Go Play -> http://jsfiddle.net/atilkan/zxjcrhga/

    Here is the HTML

    <div class="sosial-links">
        <a href="#"><i class="fa fa-facebook fa-lg"></i></a>
        <a href="#"><i class="fa fa-twitter fa-lg"></i></a>
        <a href="#"><i class="fa fa-google-plus fa-lg"></i></a>
        <a href="#"><i class="fa fa-pinterest fa-lg"></i></a>
    </div>
    

    Here is the CSS

    .sosial-links a{
        display: block;
        float: left;
        width: 36px;
        height: 36px;
        border: 2px solid #909090;
        border-radius: 20px;
        margin-right: 7px; /*space between*/
    
    } 
    .sosial-links a i{
        padding: 12px 11px;
        font-size: 20px;
        color: #909090;
    }
    

    Have Fun

    0 讨论(0)
  • 2020-12-02 05:32

    You don't need css or html tricks for it. Font Awesome has built in class for it - fa-circle To stack multiple icons together you can use fa-stack class on the parent div

    <span class="fa-stack fa-lg">
      <i class="fa fa-circle fa-stack-2x"></i>
      <i class="fa fa-flag fa-stack-1x fa-inverse"></i>
    </span> 
    

    //And we have now facebook icon inside circle:)

    0 讨论(0)
提交回复
热议问题