Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS unhover property [duplicate]

Im trying to animate a round border, that becomes square when you hover, and goes back to a circle after you unhover. Despite my best efforts, i can't seem to make it work. Here is what i have so far.

@keyframes mymove {
  from {
    border-radius: 100% 100%;
  }
  to {
    border-radius: 0px, 0px;
  }
}

@keyframes mymoveback {
  from {
    border-radius: 0px 0px;
  }
  to {
    border-radius: 100%, 100%;
  }
}

.testButt {
  width: 100px;
  height: 100px;
  background: red;
  position: relative;
  -webkit-animation: mymove 3s;
  /* Safari 4.0 - 8.0 */
  -webkit-animation-fill-mode: forwards;
  /* Safari 4.0 - 8.0 */
  animation: mymoveback 3s;
  animation-fill-mode: forwards;
}

.testButt:hover {
  -webkit-animation-fill-mode: forwards;
  animation: mymove 2s;
  animation-fill-mode: forwards;
}
<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<div class="testButt">
  <br><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log In
</div>
like image 703
Mattia Marziali Avatar asked Feb 07 '18 18:02

Mattia Marziali


People also ask

What is the difference between hover on and off in CSS?

Hover on, some CSS property animates itself to a new value; hover off, a different CSS property animates. This is a simple trick. You set transitions on both states, like this: When you hover over, the :hover transition overrides the transition set in the regular state, and that property animates.

How to remove the hover effect from a specific element?

Solutions with CSS¶ To remove the CSS hover effect from a specific element, you can set the pointer-events property of the element ... We add the :hover pseudo-class to the "button-blue" and "button-green" classes, but disable this behavior for the "disabled" class with the pointer-events property.

Why can't I use the hover pseudo-class selector with pure CSS?

The problem is that anything you change with the :hover pseudo-class selector will not (and/or should not) match elements over which you are no longer hovering. The only way you are likely to be able to do this with pure CSS is with CSS3 Animations.

What is the use of hover selector in HTML?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.


1 Answers

You over complicate it, simply use transition like this:

.testButt {
  width: 100px;
  height: 100px;
  padding:40px 0;
  text-align:center;
  box-sizing:border-box;
  background: red;
  position: relative;
  border-radius: 50%;
  transition: 0.5s;
}

.testButt:hover {
  border-radius: 0%;
}
<div class="testButt">
  Log In
</div>
like image 97
Temani Afif Avatar answered Sep 27 '22 20:09

Temani Afif