Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my transition not working on <hr>?

I have this <div> and a <hr> in an <a>. When someone hovers the whole thing it should make a fluid animation.

.wrap:hover div{
  transition: all 2s;
  opacity: 0.6;
}

.wrap:hover hr{
  transition: all 2s linear;
  width: 200px;
}

.image{
  background-color: red;
  padding: 20px;
}

hr{
  min-width: 20px;
  float: left;
}
<a class="wrap">
  <div class="image">
     Content
  </div>
  <hr class="hr-animation">
</a>

The transition works at <div>. But why is my <hr> not fluid?

like image 907
Paili Avatar asked Dec 11 '25 17:12

Paili


2 Answers

You need to use the same parameter in the original rule for hr as in the hover rule, which is width, not min-width:

.wrap:hover div{
  transition: all 2s;
  opacity: 0.6;
}

.wrap:hover hr{
  transition: all 2s linear;
  width: 200px;
}

.image{
  background-color: red;
  padding: 20px;
}

hr{
  width: 20px;
  float: left;
}
<a class="wrap">
  <div class="image">
     Content
  </div>
  <hr class="hr-animation">
</a>
like image 99
Johannes Avatar answered Dec 13 '25 06:12

Johannes


You need to specify a width to start with and put the transition for the hr, not the hover.

.wrap:hover div {
  transition: all 2s;
  opacity: 0.6;
}

.wrap:hover hr {
  width: 200px;
}

.image {
  background-color: red;
  padding: 20px;
}

hr {
  min-width: 20px;
  float: left;
  transition: all 2s linear;
  width: 20px;
}
<a class="wrap">
  <div class="image">
    Content
  </div>
  <hr class="hr-animation">
</a>
like image 39
Gerard Avatar answered Dec 13 '25 06:12

Gerard