2

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?

dippas
  • 58,591
  • 15
  • 114
  • 126
Lan Mai
  • 365
  • 1
  • 5
  • 18
  • 1
    here is responsive sizing with 1:1 ratio and `fa` scaling: http://www.codeply.com/go/cOUK6e8rRQ - is it what you tried to achieve? – Banzay Jan 08 '17 at 13:20

4 Answers4

4

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>
TylerH
  • 20,799
  • 66
  • 75
  • 101
G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
3

set a fixed width and height, and use text-align:center

i {
  border-radius: 50%;
  border: solid black;
  padding: 10px;
  width:16px;
  height: 16px;
  text-align:center
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<i class="fa fa-facebook"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-google"></i>
dippas
  • 58,591
  • 15
  • 114
  • 126
1

border-radius in the percent calculated as a percent of width and height different. try 50px for exam.

div {
  margin: .3em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2em;
  color: white;
}
.pc {
  width: 200px;
  height: 80px;
  background-color: blue;
  border-radius: 50%;
}
.px {
  width: 200px;
  height: 80px;
  background-color: blue;
  border-radius: 50px;
}
<div class="pc">%</div>
<div class="px">px</div>
Andrei Fedorov
  • 3,689
  • 2
  • 13
  • 25
  • Thank you very much, @AndreyFedorov. Thank you for your answer and your precious time. Thank you – Lan Mai Jan 08 '17 at 14:26
1

To achieve it while keeping the icon with its aspect ratio you need to assign a container to the icon with a 1:1 ratio (same width as height).

i.fa-facebook {
  padding: 10px;
  color: white;
}

.border {
  border-radius: 50%;
  border: solid white;
}

a.icon_container {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: solid white;
  text-align: center;
  float: left;
}

body {
  background: black;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<i class="fa fa-facebook border"></i>
<a href="#" class="icon_container border"><i class="fa fa-facebook"></i></a>
Alvaro
  • 9,247
  • 8
  • 49
  • 76