KB Tonmoy
KB Tonmoy

Reputation: 37

Show semi-circle effect on hovering over Bootstrap button icon

I am stuck on trying to get the hover property of a button designed the way I want. Google was unable to help me. The images below demonstrate what I am trying to achieve.

enter image description here

enter image description here

I have tried something here: https://jsfiddle.net/w32fxspr/4/ But I end up getting weird results.

i{
  padding-left: 20px;
}

a{
  margin: 20px;
  background-color: #007843 !important;
}

.custom i:hover{
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.59) !important;
  padding: 20px;
  position: absolute;
  margin-left: -20px;
  margin-top: -20px;
  transition: .1s ease;   
}
<!DOCTYPE html>
<html>
<head>
  <title>Button</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog==" crossorigin="anonymous" />

</head>
<body>
    <a href="#" class="btn btn-primary custom">
      CONTACT US <i class="fa fa-angle-right"></i>
    </a>
</body>
</html>

Upvotes: 1

Views: 510

Answers (1)

FluffyKitten
FluffyKitten

Reputation: 14312

You can add the hover effect using the :before pseudo element for the button, and we will use absolute positioning to place this over the button on hover:

.custom {
  position: relative;
  overflow: hidden;
  border: none!important;
}

.custom:before {
  content: " ";
  display: block;
  height: 80px;
  width: 80px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.30) !important;
  position: absolute;
  right: -80px;
  top: -22px;
  transition: .1s ease;
}

.custom:hover:before {
  right: -45px;
}

/* Your existing CSS */
i { padding-left: 20px; }
a{ margin: 20px; background-color: #007843 !important; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />

<a href="#" class="btn btn-primary custom">
  CONTACT US <i class="fa fa-angle-right"></i>
</a>

How this works:

  • We make the button (.custom) position: relative; so we can place an element over it using absolute position. We also add overflow: hidden; to contain the effect inside the button only.
  • We make .custom:before a block element that contains a semi-transparent circle and use absolute positioning to place it where we want.
  • To start we position the circle to the far right of the button using right: -80px; so it is not visible.
  • Then on hovering the button .custom:hover:before, we change right: -45px; for the circle to appear.

Upvotes: 3

Related Questions