1

I was wondering how I could get all of my bars to turn black when I hover over the edge of the button. At the moment I can only get one bar to turn black when I hover over the middle bar, but I cannot figure out how to make all of the bars turn black as soon as the mouse hovers over the actual button.

Here is the jsfiddle: https://jsfiddle.net/nc0L83am/

Here is the code:

<html>
<head>
<link rel="stylesheet" media="all" type="text/css" href="drop.css">
<style>
.c-hamburger {
  display: block;
  position: relative;
  overflow: hidden;
  margin: 0;
  padding: 0;
  width: 64px;
  height: 64px;
  font-size: 0;
  text-indent: -9999px;
  appearance: none;
  box-shadow: none;
  border-radius: none;
  border: none;
  cursor: pointer;
  transition: background 0.1s;
  border-radius:10px;    
  background: blue;
}
.c-hamburger:focus {
  outline: none;
}

.c-hamburger span:hover{background: black;}

.c-hamburger span {
  display: block;
  position: absolute;
  top: 28px;
  left: 10px;
  right: 10px;
  height: 8px;
  background: #e6e6e6;
  border-radius:100px;
}

.c-hamburger span::before,
.c-hamburger span::after {
  position: absolute;
  display: block;
  left: 0;
  width: 100%;
  height: 8px;
  background-color: #e6e6e6;
  content: "";
  border-radius:100px;    
}

.c-hamburger span::before {
  top: -15px;
}

.c-hamburger span::after {
  bottom: -15px;
}

.c-hamburger--htx {

}

.c-hamburger--htx span {
  transition: background 0s 0.1s;
}

.c-hamburger--htx span::before,
.c-hamburger--htx span::after {
  transition-duration: 0.1s, 0.1s;
  transition-delay: 0.1s, 0s;
}

.c-hamburger--htx span::before {
  transition-property: top, transform;
}

.c-hamburger--htx span::after {
  transition-property: bottom, transform;
}

/* active state, i.e. menu open */
.c-hamburger--htx.is-active {
  background-color: #cb0032;
}

.c-hamburger--htx.is-active span {
  background: none;
}

.c-hamburger--htx.is-active span::before {
  top: 0;
  transform: rotate(45deg);
  background: white;
}

.c-hamburger--htx.is-active span::after {
  bottom: 0;
  transform: rotate(-45deg);
  background: white;
}

.c-hamburger--htx.is-active span::before,
.c-hamburger--htx.is-active span::after {
  transition-delay: 0s, 0.1s;
}
</style>
</head>
<body>

<button class="c-hamburger c-hamburger--htx">
  <span>toggle menu</span>
</button>

<script>
(function() {

  "use strict";

  var toggles = document.querySelectorAll(".c-hamburger");

  for (var i = toggles.length - 1; i >= 0; i--) {
    var toggle = toggles[i];
    toggleHandler(toggle);
  };

  function toggleHandler(toggle) {
    toggle.addEventListener( "click", function(e) {
      e.preventDefault();
      (this.classList.contains("is-active") === true) ? this.classList.remove("is-active") : this.classList.add("is-active");
    });
  }

})();
</script>
</body>
INeedHelp
  • 141
  • 1
  • 1
  • 8

1 Answers1

1

Move the hover to the button and not the span

.c-hamburger:hover span, 
.c-hamburger:hover span::before,
.c-hamburger:hover span::after { 
    background: black; 
}
epascarello
  • 204,599
  • 20
  • 195
  • 236
  • Would there be a way to get them to do it all at the same time? – INeedHelp Jan 13 '16 at 04:37
  • Oops, I had a 0.1 second delay on it. Thanks for the help! – INeedHelp Jan 13 '16 at 04:44
  • 1
    Damn, got to it before I could. :) Note the syntax, putting the ::after and ::before elements after the hover - fancy css selectors! http://stackoverflow.com/questions/5777210/how-to-write-hover-condition-for-abefore-and-aafter – tigeruppercut Jan 13 '16 at 04:52