Przemek Wojtas
Przemek Wojtas

Reputation: 1371

Css 3 transition between arrows

I have a simple arrow which is like this:

>

and on hover I want it to expand to look like this:

->

of course without the gap between them.

This has to be a transition + animation between them to be smooth. Here's what I have so far

My Work

body,
html {
  margin: 0;
  padding: 0;
  max-width: 100%;
  max-height: 100%;
  overflow-x: hidden;
  position: relative;
  background-color: black;
}

.button {
  display: inline-block;
  vertical-align: middle;
  border-radius: 50%;
  margin: 6em 0 0;
  padding: 0;
  text-align: center;
}

.left {
  display: inline-block;
  width: 3em;
  height: 3em;
  border: 0.5em solid #333;
  border-radius: 50%;
  margin-right: 1.5em;
}

.left:after {
  content: '';
  display: inline-block;
  margin-top: 0.90em;
  margin-left: 0.6em;
  width: 0.8em;
  height: 0.8em;
  border-top: 0.5em solid #333;
  border-right: 0.5em solid #333;
  -moz-transform: rotate(-135deg);
  -webkit-transform: rotate(-135deg);
  transform: rotate(-135deg);
}

.right {
  color: white;
  display: inline-block;
  width: 3em;
  height: 3em;
  border: 0.5em solid #333;
  border-radius: 50%;
  margin-left: 1.5em;
}

.right:after {
  content: '';
  display: inline-block;
  margin-top: 0.90em;
  margin-left: -0.6em;
  width: 0.8em;
  height: 0.8em;
  border-top: 0.5em solid #333;
  border-right: 0.5em solid #333;
  -moz-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}

.right:hover {
  content: '';
  display: inline-block;
  margin-top: 0.90em;
  margin-left: -0.6em;
  width: 2em;
  height: 2em;
  border-top: 0.5em solid #333;
  border-right: 0.5em solid #333;
  -moz-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}
<body>
  <div class="button">
    <span class="left"></span>
  </div>
  <div class="button">
    <span class="right"></span>
  </div>
</body>

Any ideas how can I achieve smooth transition and animation from between those 2 arrows?

Upvotes: 1

Views: 3409

Answers (1)

zagzter
zagzter

Reputation: 327

Well, hope this help. I did it by insert another pseudo class onhover of your right class.

.right:hover:before {
    content: '';
    height: 0.5em;
    width: 1.4em;
    background-color: #333333;
    display: inline-block;
    transform: translate(6px,-6px);
    max-width: 2em;
    transition: 0.5s all ease-in-out;
}
.right:before {
    content: '';
    transition: 0.5s all ease-in-out;
    max-width: 0em;
}

If you insert this, you must remove .right:hover. Check this pen.

Upvotes: 3

Related Questions