可折叠 Icon/Content 悬停时颜色变化

Collapsible Icon/Content Color Change on Hover

我正在处理 'collapsible' 内容(常见问题解答下拉列表)。在预单击的 'button' 上,我有一个 'plus' 图标(按下按钮后图标变为 'negative' 图标)。我想要的是预单击按钮 'plus' 图标在按钮悬停时改变颜色(即变成白色)。我不确定如何修改 CSS 以在悬停时更改图标。

我试过:

.collapsible:after, .hover{
  color: $light;
}

但这只能扭转问题...在此先感谢您!下面的代码。

var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    if (content.style.display === "block") {
      content.style.display = "none";
    } else {
      content.style.display = "block";
    }
  });
}
/* TARGET ICON */
.collapsible:after {
  content: '795'; /* Unicode character for "plus" sign (+) */
  color: black;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

.active:after {
  content: "96"; /* Unicode character for "minus" sign (-) */
  color: white;
}

/* Style the button that is used to open and close the collapsible content */
.collapsible {
  background-color: white;
  color: black;
  cursor: pointer;
  padding: 10px 18px;
  width: 100%;
  border: solid;
  border-width: thin;
  border-radius: 5px;
  margin-bottom: 5px;
  text-align: left;
  outline: none;
  font-size: 24px;
}

/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active, .collapsible:hover {
  background-color: black;
  color: white;
}

/* Style the collapsible content. Note: hidden by default */
.content-faq {
  padding: 0px 22px;
  border-radius: 5px;
  margin-bottom: 15px;
  margin-top: -6px;
  max-height: 0;
  transition: max-height 0.2s ease-out;
  background-color: #f1f1f1;
}
<button class="collapsible">Some Question</button>
  <div class="content-faq">
    <p>Some Answer</p>
  </div>

使用 .collapsible:hover::after 到 select 使用 ::after

创建的 hover 上的内容

As the greyish color is of the symbol you used which is inherited so changed that to simple + - for demo to show effect only .
You can use any symbol but without inherit color

var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    this.classList.toggle("active");
    var content = this.nextElementSibling;
    if (content.style.display === "block") {
      content.style.display = "none";
    } else {
      content.style.display = "block";
    }
  });
}
/* TARGET ICON */

.collapsible::after {
  content: '+';
  /* Unicode character for "plus" sign (+) */
  color: black;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

.active:after {
  content: "12";
  /* Unicode character for "minus" sign (-) */
  color: white;
}


/* Style the button that is used to open and close the collapsible content */

.collapsible {
  background-color: white;
  color: black;
  cursor: pointer;
  padding: 10px 18px;
  width: 100%;
  border: solid;
  border-width: thin;
  border-radius: 5px;
  margin-bottom: 5px;
  text-align: left;
  outline: none;
  font-size: 24px;
}


/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */

.active,
.collapsible:hover {
  background-color: black;
  color: white;
}




/* Style the collapsible content. Note: hidden by default */

.content-faq {
  padding: 0px 22px;
  border-radius: 5px;
  margin-bottom: 15px;
  margin-top: -6px;
  max-height: 0;
  transition: max-height 0.2s ease-out;
  background-color: #f1f1f1;
}

.collapsible:hover::after {
  color: white;  
}
<button class="collapsible">Some Question</button>
<div class="content-faq">
  <p>Some Answer</p>
</div>