当我将鼠标悬停在按钮边缘时,如何使所有的条形图变黑



当我将鼠标悬停在按钮边缘时,我想知道如何使所有的条形图变黑。目前,当我悬停在中间条上时,我只能让一个条变黑,但我不知道如何在鼠标悬停在实际按钮上时使所有条变黑。

这是jsfiddle:https://jsfiddle.net/nc0L83am/

这是代码:

<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>

将悬停移动到按钮,而不是span

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

最新更新