0

Hi guys so I'm trying to create scroll to Top button in react.js and I have manage to finished the component but the problem is I can't make the icon vertically center on the circle button. How can I fix it ? I've tried to align the item to center. Is it because the Icon itself have some kind of padding on top ?

Here's my code:

  return (
        <button onClick={ScrollToTop} className="ButtonToTop" aria-hidden="true" style={{display: isVisible ? 'inline' : 'none'}}>
            <BiArrowToTop/>
        </button>
    )

My css code:

.ButtonToTop{
    align-items: center;
    position: fixed; 
    width: 50px;
    right: 10px;
    bottom: 40px;
    height: 50px;
    font-size: 33px;
    z-index: 1;
    cursor: pointer;
    background-color: #967A50;
    color: #10255A;
}
Kim San
  • 575
  • 7
  • 22

1 Answers1

0

Update

You are setting style={{ display: isVisible ? "inline" : "none" }} which resets the display to inline. Just set it to flex and add the css below (updated)

style={{ display: isVisible ? "flex" : "none" }}


Use Flex to easily align it to center

.ButtonToTop{
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed; 
    width: 50px;
    right: 10px;
    bottom: 40px;
    height: 50px;
    font-size: 33px;
    z-index: 1;
    cursor: pointer;
    background-color: #967A50;
    color: #10255A;
}

Imanpal Singh
  • 1,105
  • 1
  • 12
  • 22