horizontal color switch on hover

In this example below you will see how to do a horizontal color switch on hover with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by mush_el, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright mush_el ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>horizontal color switch on hover</title>
  <link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <span id="special">
  <span class="special">W</span>
  <span class="special">h</span>
  <span class="special">a</span>
  <span class="special">t</span>
</span>

<a class="cool" href="">if you hover you might say, well this is cool!</a>
<br>


<div class="flip">
  <div class="back">
    i am a thing you wanna hover on because i flip
  </div>
  <div class="front">This is the front</div>
</div>

<div class="q-bert_container">
  <div class="q-bert_top">Michelle what are you doing?</div>
  <div class="q-bert_top"><a href="">Let this section skew...</a></div>
  <div class="q-bert_top"><a href="">Does it mess with you?</a></div>
  <div class="q-bert_top"><a href="">I kind of like it when you hover :)</a></div>
</div>
  <script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/mush_el/horizontal-color-switch-on-hover-VLQPNv */
.border-box {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
html {
  font-family: 'Montserrat', sans-serif;
}
#special {
  font-weight: bold;
  color: #f0c;
  border-bottom: 2px solid black;
  text-decoration: none;
  margin: 20px;
}
.change {
  color: black;
  border-color: #f0c;
  position: relative;
  background-position: 0% 0;
  -webkit-transition: background-position 0.5s ease-out;
  -moz-transition: background-position 0.5s ease-out;
  -ms-transition: background-position 0.5s ease-out;
  -o-transition: background-position 0.5s ease-out;
  transition: background-position 0.5s ease-out;
}
a.cool {
  color: black;
  background-size: 200.22% auto;
  -webkit-background-size: 200.22% auto;
  -moz-background-size: 200.22% auto;
  background-position: 0% 0;
  background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 50%, #DDD 50%);
  transition: background-position 0.5s ease-out;
  -webkit-transition: background-position 0.5s ease-out;
  font-size: 20px;
  text-decoration: none;
  padding: 10px 20px;
}
a:hover {
  background-position: -99.99% 0;
  padding: 10px 20px;
}
.btn {
  margin: 100px;
  padding: 10px 20px;
  border-bottom: 2px solid #000;
  color: #f0c;
}
.hover {
  position: relative;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.flip {
  display: block;
  width: 200px;
  height: 200px;
  margin: 20px;
  position: relative;
  overflow: hidden;
  float: left;
}
.back {
  background: #f0c;
  color: #fff;
  width: 200px;
  height: 200px;
  z-index: 5;
  position: absolute;
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
  backface-visibility: hidden;
  padding: 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.front {
  color: #fff;
  -webkit-transform: rotateY(-180deg);
  -moz-transform: rotateY(-180deg);
  transform: rotateY(-180deg);
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  transition: all .5s;
  background: #000;
  width: 200px;
  height: 200px;
  padding: 10px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.flip:hover .front {
  -webkit-transform: rotateY(0deg);
  -moz-transform: rotateY(0deg);
  transform: rotateY(0deg);
}
.flip:hover .back {
  backface-visibility: hidden;
  -webkit-transform: rotateY(-180deg);
  -moz-transform: rotateY(-180deg);
  transform: rotateY(-180deg);
}
.q-bert_container {
  float: right;
  width: 400px;
  background: #000;
  height: 100vh;
  margin-top: -32px;
}
.q-bert_top {
  padding: 20px;
  border-bottom: 1px solid #ccc;
  color: #fff;
  -webkit-transform: skewY(2.5deg);
  text-align: right;
}
.q-bert_top a {
  background-size: 400px 50px;
  color: #fff;
  overflow: hidden;
  background-image: linear-gradient(to right, rgba(255, 255, 255, 0) 50%, #111 50%);
  -webkit-transform: translate3d(-225px, 0px, 0px);
  -moz-transform: translate3d(-225px, 0px, 0px);
  -ms-transform: translate3d(-225px, 0px, 0px);
  -o-transform: translate3d(-225px, 0px, 0px);
  transform: translate3d(-225px, 0px, 0px);
  transition: background-size 0.8s ease-out;
  text-decoration: none;
  padding: 20px;
  margin: 0px -20px 0px -20px;
  font-size: 16px;
}
.q-bert_top a:hover {
  background-size: 0px 0px;
  -webkit-transform: translate3d(-5px, 0px, 0px);
  -moz-transform: translate3d(-5px, 0px, 0px);
  -ms-transform: translate3d(-5px, 0px, 0px);
  -o-transform: translate3d(-5px, 0px, 0px);
  transform: translate3d(-5px, 0px, 0px);
  padding: 20px;
  margin: 0px -20px 0px -20px;
}


/*Downloaded from https://www.codeseek.co/mush_el/horizontal-color-switch-on-hover-VLQPNv */

  

$('.special').hover(function(){ 
  $(this).addClass('change'); },
  function(){ $(this).removeClass('change'); }
);

$('.btn').hover(function(){ 
  $(this).addClass('hover'); },
  function(){ $(this).removeClass('hover'); }
);

Comments