Search code examples
htmlcssborderfont-awesome

Make Font Awesome icons in a circle border with right 1:1 ratio


In some case, if the ratio of the icon is not 1:1, the border is not a circle anymore.

Here's an example:

enter image description here

I'm currently using:

HTML:

.socials
      a(href='#') <i class="fa fa-facebook"></i>
      a(href='#') <i class="fa fa-twitter"></i>
      a(href='#') <i class="fa fa-google"></i>

SASS:

      border-radius: 50%
      border: solid white
      padding: 10px

Is there anyway that I can use CSS to fix the problem?


Solution

  • You need to set width, height, line height, & text-align to center the icon. icon will need also vertical-align reset to middle.

    Avoid padding in pixels, but use width/height/line-height in em or rem. You can then change font-size and keep the ratio without updating other values.

    a /* or selector a .fa */
      {  
      font-size:3em;
      border-radius: 50%;
      border: solid white;
      color: white;
      line-height: 2em;
      width: 2em;
      height: 2em;
      text-align: center;
      display: inline-block;
        transition:0.5s;
    }
    /* demo purpose */
    a:hover {font-size:2em}
    .fa {
    /* optionnal vertical-align: middle;*/
    }
    body {
      background: #333
    }
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
    <a href="#"><i class="fa fa-facebook"></i></a>
    <a href="#"><i class="fa fa-twitter"></i></a>
    <a href="#"> <i class="fa fa-google"></i>
    </a>