You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地复现navbar时hover背景不切换蓝色问题求助

导航栏鼠标悬停背景不显示蓝色的解决方法

问题出在你的CSS使用了Sass嵌套语法,但浏览器原生不支持这种语法,导致:hover样式无法生效。以下是具体解决步骤:

核心原因

你写的CSS包含Sass特有的嵌套规则(比如.et-hero-tab内部的&:hover,.et-hero-tabs内部嵌套h1/h3),这些语法需要经过编译才能转换成浏览器可识别的标准CSS。如果本地没有配置Sass编译流程,浏览器会忽略这些嵌套的样式规则。

解决方法

方法1:编译Sass为标准CSS

如果继续使用Sass语法,需要安装Sass编译器(比如通过npm安装sass),将.scss文件编译为.css后再引入页面。

方法2:手动展开嵌套语法

直接将嵌套的CSS代码展开为浏览器支持的普通写法,修改后的完整CSS如下:

body {
  font-family: "Century Gothic", 'Lato', sans-serif;
}

a {
  text-decoration: none;
}

.et-hero-tabs,
.et-slide {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  position: relative;
  background: #eee;
  text-align: center;
  padding: 0 2em;
}

.et-hero-tabs h1,
.et-slide h1 {
  font-size: 2rem;
  margin: 0;
  letter-spacing: 1rem;
}

.et-hero-tabs h3,
.et-slide h3 {
  font-size: 1rem;
  letter-spacing: 0.3rem;
  opacity: 0.6;
}

.et-hero-tabs-container {
  display: flex;
  flex-direction: row;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 70px;
  background: #fff;
  z-index: 10;
}

.et-hero-tabs-container--top {
  position: fixed;
  top: 0;
}

.et-hero-tab {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  color: #FF0000;
  letter-spacing: 0.1rem;
  transition: all 0.5s ease;
  font-size: 0.8rem;
}

.et-hero-tab:hover {
  color: #FF0000;
  background: rgba(102, 177, 241, 0.8);
  transition: all 0.5s ease;
}

.et-hero-tab-slider {
  position: absolute;
  bottom: 0;
  width: 0;
  height: 6px;
  background: #66B1F1;
  transition: left 0.3s ease;
}

@media (min-width: 800px) {
  .et-hero-tabs h1,
  .et-slide h1 {
    font-size: 3rem;
  }
  .et-hero-tabs h3,
  .et-slide h3 {
    font-size: 1rem;
  }
  .et-hero-tab {
    font-size: 1rem;
  }
}

验证说明

替换上述CSS后,鼠标悬停导航项时,背景会正常显示蓝色。JS部分的逻辑和加载顺序没有问题,悬停效果由CSS控制,和JS无关。

内容的提问来源于stack exchange,提问作者Beatdown

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 15:50:27