Roberto Roberto - 4 months ago 28
CSS Question

cicrle animation with css

I want to create animation just like that. However it doesn't look like it should. Here is fiddle of my code. Please help.

.effect-1 {
position: relative;
height: 100px;
width: 100px;
margin: 100px;
border-radius: 50%;
display: block;
text-align: center;
line-height: 100px;
background-color: black;
}

.effect-1::after {
position: absolute;
top: -10px;
left: -10px;
height: 100%;
width: 100%;
padding: 10px;
border-radius: 50%;
box-shadow: 0 0 0 5px rgba(0, 0, 0, 0.8);
transform: scale(0.7, 0.7);
transition: all 0.2s;
}

Answer

I would recommend altering the scale transform property on hover, instead of changing height/width in pixels (because that will affect the layout flow) whereas the transform properly creates a custom layer for your object:

.effect {
  position: relative;
  height: 100px;
  width: 100px;
  line-height: 100px;
  border-radius: 50%;
  display: block;
  text-align: center;
  background-color: black;
  color: white;
  font-size: 2em;
  text-decoration: none;
  margin: 1em;
}

.effect::before {
  content: '';
  position: absolute;
  top:0; bottom: 0; left: 0; right: 0;
  margin: auto;
  height: 100%; width: 100%;
  border:5px solid black;
  border-radius: inherit;
  box-sizing: border-box;
  transform: scale(0.5);
  transition: .3s;
}

.effect:hover::before {
  transform: scale(1.2);
}
<a href="#" class="btn effect">M</a>

Also, the transition property should be added to the static state instead of hover state for optimal results.