如何去除静态 类 上的悬停效果?

How to remove hover effects on static classes?

我正在尝试构建一个类似于在类星体中找到的切换按钮,但我很难使用堆叠悬停效果。

我对所有按钮都有悬停效果(第一个和最后一个子项的外边框变圆),但是当按钮处于活动状态时(我认为)有不同的悬停颜色。目前它们相互堆叠,我不确定如何删除静态 css 悬停效果。

我怎样才能删除原来的悬停效果并只具有 is-active 悬停效果?

干杯!

这是类星体按钮的示例:

ButtonToggle.vue

<template>
  <div class="c-button-toggle-wrapper">
    <button
      :class="[option.value === selectedOption ? 'is-active' : '', 'c-button']"
      v-for="option in options"
      :key="option"
      :modelValue="modelValue"
      :option="options"
      @click="selected(option.value)"
    >
      {{ option.label }}
    </button>
  </div>
</template>

<style lang="sass" scoped>
.c-button-toggle-wrapper
  display: flex
  justify-content: center
  align-items: center
  background: lavender
  width: max-content
  padding: 8px

.c-button
  background: transparent
  font-size: 14px
  font-weight: 500
  color: rgba(36, 42, 56, 0.75)
  border: none
  line-height: 1.715em
  text-transform: uppercase
  padding: 6px 16px
  margin: 0
  cursor: pointer
  &:hover
    transition: .4s
    background: rgba(0, 0, 0, 0.075)
  &:first-child
    &:hover
      border-top-left-radius: 2px
      border-bottom-left-radius: 2px
  &:last-child
    &:hover
      border-top-right-radius: 2px
      border-bottom-right-radius: 2px

.is-active
  background: white
  border-radius: 4px
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.16)
  border: none
  &:hover
    transition: .4s
    background: rgba(0, 0, 0, 0.075)
</style>

<script>
export default {
  name: "ButtonToggle",
  props: {
    modelValue: { type: undefined, required: true },
    options: { type: Array, required: true },
  },
  data() {
    return {
      selectedOption: null,
    };
  },
  computed: {},
  methods: {
    selected(option) {
      this.selectedOption = option;
      console.log(`selectedOption`, this.selectedOption);
      this.$emit("update:modelValue", this.selectedOption);
    },
  },
};
</script>

CodeSandbox

使用 .not() 伪 class.

所以在你的情况下: .c-button.not(.is-active):hover {...}