0

I am trying to create a circle around my font-awesome share icons. I decided to go with a css approach, because I could not figure out how to do other approaches with React FontAwesome

<FacebookShareButton 
    className='m-1' //bootstrap margin 1
    url={siteUrl}
>
    <FontAwesomeIcon className='faCircle' size="2x" icon={faFacebookF} />
</FacebookShareButton>
.faCircle {
    display: inline-block;
    border-radius: 50%;
    box-shadow: 0px 0px 2px #888;
    padding: 0.25em 0.3em;
    background-color: transparent;
    width: 1.2em !important;
    height: 1.2em;
    overflow: visible;
}

My code produces the font awesome icons, but the border-radius of 50% ends up trimming off the sides of the icons.

(Effect is most noticeable on LinkedIn icon)

enter image description here

If I remove the margin, the icons get bigger, but are still trimmed by the border-radius

This issue happens on Safari, but not on chrome or firefox. On firefox, the icons appeared fully if I set the width big enough


UPDATE (with temporary hacky solution)

In safari I have to do some really finicky stuff in order to stop white padding from overlaying the icon inside the circle. I have to specify really specific widths and heights to prevent this and these width and heights aren't even the same value. If anyone could post a less hacky solution that this one that would be appreciated.

      <FacebookShareButton 
        className="m-md-1 m-1"
        url={siteUrl}
      >
        <div className='faCircleContainer'>
          <FontAwesomeIcon className='faCircle' size="2x" icon={faFacebookF} />
        </div>
      </FacebookShareButton>
.faCircle {
    width: 1.2em !important;
    padding: 0.1em;
}

.faCircleContainer {
    padding: 0.25em 0.3em;
    border-radius: 50%;
    box-shadow: 0px 0px 4px #888;
}

.react-share__ShareButton{
    padding: 5px !important;
}
Sam
  • 1,765
  • 11
  • 82
  • 176
  • is there a max-width set ? and if so try overriding that? I had a similar issue that i solved with max-width and height not sure if it ll work for you. – Damini Ganesh Jun 08 '20 at 23:07

1 Answers1

0

You should not style FontAwesomeIcon component/icon directly. Paddings and border-radius are disturbing actual icon. You should create a separate wrapper for each icon and apply your 'faCircle' class to this wrapper. So I believe in your case, moving class from FontAwesomeIcon to FacebookShareButton should work.

Here's screenshot from font-awesome page, when I edited it directly by styling 'info-icons' wrapper.

enter image description here

.info-icons {
display: inline-block;
width: 100px;
height: 100px;
padding: 20px;
text-align: center;
border-radius: 50%; 
background: #fff;
border: 1px solid;
}
Kate
  • 96
  • 5
  • This is almost a solution, but in safari I have to do some really finicky stuff in order to stop white padding from overlaying the icon inside the circle. I have to specify really specific widths and heights to prevent this. I'm going to edit my question and post the "solution" I came up with, but it's really hacky and I don't like it – Sam Jun 16 '20 at 21:22
  • Could you copy and paste the code instead of a screenshot? – Sam Jun 16 '20 at 21:31