How to move the position edges after the Hover?

Asked

Viewed 299 times

1

I have this div with edges in the corners and wanted the right edge to be down and the left edge to be up when the div is on hover but I couldn’t apply the effect.

Below is what I tried:

div.classe {
    position: relative;
    float: left;
    padding: 0 10px;
    width: 80%;
    height: 100px;
    background: rgba(38, 166, 91, 0.5);
    margin-top: 30px;
    transition: all 0.4s  ease-in-out;
   
}
div.classe:after {
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    bottom: 0;
    left: 0;
    border-left: 4px solid #000;
    border-bottom: 4px solid #000;
    z-index:-1;
    margin-bottom:-4px;
    margin-left: -4px;
    border-color
}
div.classe:before {
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    top: 0;
    right: 0;
    border-right: 4px solid #000;
    border-top: 4px solid #000;
    z-index:-1;
    margin-top:-4px;
    margin-right: -4px;
}
div.classe:hover{
  transform: translateY(-20px);
}
div.classe:hover:before{
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    right: 0;
    top: 0;
    border-right: 4px solid #000;
    border-top: 4px solid #000;
    z-index:-1;
    margin-top:-4px;
    margin-right: -4px;
    border-color
}
div.classe:hover:after{
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    bottom: 0;
    left: 0;
    border-left: 4px solid #000;
    border-bottom: 4px solid #000;
    z-index:-1;
    margin-bottom:-4px;
    margin-left: -4px;
}
<div class="classe">
texto qualquer
</div>

2 answers

2


You can put the effect after the :hover using ::after or ::before.

Following example:

div.classe {
    position: relative;
    float: left;
    padding: 0 10px;
    width: 80%;
    height: 100px;
    background: rgba(38, 166, 91, 0.5);
    margin-top: 30px;
    transition: all 0.4s ease-out;
   
}
div.classe:after {
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    bottom: 0;
    left: 0;
    border-left: 4px solid #000;
    border-bottom: 4px solid #000;
    z-index:-1;
    margin-bottom:-4px;
    margin-left: -4px;
    border-color
}

div.classe:before {
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    top: 0;
    right: 0;
    border-right: 4px solid #000;
    border-top: 4px solid #000;
    z-index:-1;
    margin-top:-4px;
    margin-right: -4px;
}

div.classe:hover{
  transform: translateY(-20px);
  -webkit-transition: 0.5s ease-in;
  -moz-transition: 0.5s ease-in;
  -o-transition: 0.5s ease-in;
  transition: 0.5s ease-in;
}

div.classe:hover::after{
  border:none;
  content:"";
  position: absolute;
  top: 0;
  left: 0;
  border-left: 4px solid #000;
  border-top: 4px solid #000;
}

div.classe:hover::before{
  transform: translateY(30px);
  border:none;
  content:"";
  position: absolute;
  bottom: 0;
  right: 0;
  border-right: 4px solid #000;
  border-bottom: 4px solid #000;
}
<div class="classe">
  <p>
  texto qualquer
  </p>
</div>

Following the suggestion of Gabriel. H follows a version with "delay" in the transition:

div.classe {
    position: relative;
    float: left;
    padding: 0 10px;
    width: 80%;
    height: 100px;
    background: rgba(38, 166, 91, 0.5);
    margin-top: 30px;
    transition: all 0.4s ease-out;
   
}
div.classe:after {
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    bottom: 0;
    left: 0;
    border-left: 4px solid #000;
    border-bottom: 4px solid #000;
    z-index:-1;
    margin-bottom:-4px;
    margin-left: -4px;
    border-color
}

div.classe:before {
    content:"";
    height: 70px;
    width: 70px;
    position: absolute;
    top: 0;
    right: 0;
    border-right: 4px solid #000;
    border-top: 4px solid #000;
    z-index:-1;
    margin-top:-4px;
    margin-right: -4px;
}

div.classe:hover{
  transform: translateY(-20px);
  -webkit-transition: 0.5s ease-in;
  -moz-transition: 0.5s ease-in;
  -o-transition: 0.5s ease-in;
  transition: 0.5s ease-in;
}

div.classe:hover::after{
  border:none;
  content:"";
  position: absolute;
  top: 0;
  left: 0;
  border-left: 4px solid #000;
  border-top: 4px solid #000;
  -webkit-transition: 0.5s ease-in;
  -moz-transition: 0.5s ease-in;
  -o-transition: 0.5s ease-in;
  transition: 0.5s ease-in;
}

div.classe:hover::before{
  transform: translateY(30px);
  border:none;
  content:"";
  position: absolute;
  bottom: 0;
  right: 0;
  border-right: 4px solid #000;
  border-bottom: 4px solid #000;
  -webkit-transition: 0.5s ease-in;
  -moz-transition: 0.5s ease-in;
  -o-transition: 0.5s ease-in;
  transition: 0.5s ease-in;
}
<div class="classe">
  <p>
  texto qualquer
  </p>
</div>

  • This already solved my problem a lot, only one question had how to make a smoother transition? type of sliding around the edges?

  • I edited the question see now.

2

Friend if you want a smoother transition, add this

-webkit-transition: 0.5s ease-in;
-moz-transition: 0.5s ease-in;
-o-transition: 0.5s ease-in;
transition: 0.5s ease-in;

css from div.class, div.class:Hover after and before

  • +1, I was researching here kkk I will edit my reply adding a version with this "delay"

  • kk , this resolution worked for you?

  • 1

    I guessed in my reply, take a look at how it turned out.

  • 1

    Quiet , I wasn’t sure if it would work because I never used kkk myself

Browser other questions tagged

You are not signed in. Login or sign up in order to post.