Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hover colour transition slide effect

I have a link that changes colour when mouse hovers over it and i am fully conformable with the coding for this however i would like the however effect to slide down as oppose to just change colour. how is this possible with css. I have looked around stack overflow but only able to find instances where people use background images and alter the its position. Is that the only way to make this possible?

It is difficult to articualte what i am trying to achieve but it is on show on this website weblounge.be the effect that i am trying to achieve is on the two links on the homepage

#contactlink {
  display: inline-block;
  font-weight: 700;
  text-transform: uppercase;
  padding: 11px 51px;
  border: 1px solid #fff;
  -webkit-transition: .2s;
          transition: .2s;
  margin-left: 78px;
  margin-top: 40px;
  float: left;
  color: #FFF;
  text-decoration: none;
  -webkit-transition: .2s;
          transition: .2s;
  text-decoration: none;
  opacity: 0;
}
#contactlink:hover {
  background-color: #FFF;
  color: #666;
  border: 1px solid #fff;
  -webkit-transition: .2s;
          transition: .2s;
}
<a href="#contact" class="smoothScroll" id="contactlink">Let's talk</a>

https://jsfiddle.net/6t3quy4w/5/

like image 625
danmorris Avatar asked Mar 18 '26 20:03

danmorris


1 Answers

The website you linked does theirs by having the :before pseudo-element transition its scale over top of the button. It also required having a span inside the button so that its z-index could be set on top of the :before element. Here is an example:

a.color-change {
  display: inline-block;
  padding: 15px;
  color: black;
  background-color: white;
  position: relative;
  padding: 15px;
  border: 1px solid black;
  text-decoration: none;
  z-index: 0;
}

a.color-change:before {
  content: ' ';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #777;
  transform: scale(1, 0);
  transition: all .25s ease-out;
  transform-origin: center top;
  z-index: 0;
}

a.color-change:hover:before {
  transform: scale(1);
}

a.color-change span {
  z-index: 1;
  position: relative;
}
<a href="#" class="color-change"><span>Hover Over Me</span></a>
like image 58
CodingWithSpike Avatar answered Mar 20 '26 08:03

CodingWithSpike