html 背景颜色仅在chrome和firefox中检查时显示

kiayqfof  于 2022-12-16  发布在  其他
关注(0)|答案(1)|浏览(105)

我遇到了一个与背景色有关的奇怪问题,在chrome或firefox浏览器中查看html文件时,背景色不适用于商店链接(在.header__shop选择器中),但当我检查它并将鼠标悬停在元素上时,背景色突然出现在chrome和firefox中。HTML:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      href="https://fonts.cdnfonts.com/css/helvetica-neue-9?styles=49034,49031,49033,49035,49032,49036,49038,49040,49042,49044,49037,49039,49041,49043,49045,49046"
      rel="stylesheet"
      crossorigin
    />
    <link rel="stylesheet" href="style.css" />
    <title>Assignment 4</title>
  </head>
  <body>
    <header class="header">
      <div class="header__top-ribbon">
        <a href="#" class="header__logo margin-left-small margin-right-small"
          ><img src="./images/logo.png" alt="Motorolo logo"
        /></a>
        <a href="#">Explore </a>
        <a class="header__shop" href="#">Shop</a>
        <a href="#">Customer Hub</a>
      </div>
    </header>
  </body>
</html>

CSS:

:root {
  --header-active-background: #f2f2f2;
  --header-link-color: #00000099;
  --black: #000000;
}
* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
html {
  font-size: 62.5%;
}
header a:link,
header a:visited {
  display: block;
  height: 100%;
  display: flex;
  align-items: center;
  text-decoration: none;
  color: var(--header-link-color);
  font-size: 1.2rem;
  padding: 0 1.2rem;
  letter-spacing: 0.03125rem;
}
header a:link {
  transition: all 0.5s;
}
header a:hover {
  color: rgba(0, 0, 0, 0.95);
}
/* UTILS */
.margin-left-small {
  margin-left: 2rem !important;
}
.margin-right-small {
  margin-right: 2rem !important;
}
/* header */
.header__logo img {
  height: 45%;
}
.header {
  position: fixed;
  top: 0;
}
.header__top-ribbon {
  height: 6.4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header__shop {
  background-color: var(--header-active-background);
  font-weight: bold;
  color: var(--black) !important;
}
.header__logo {
  padding: 0 !important;
}

我试过把!important放进去

background-color: var(--header-active-background);

.header__shop

选择器,它没有工作。尝试采取屏幕截图和剪切工具,但采取的屏幕截图显示了背景色,即使它不是有眼睛看到的!

jhkqcmku

jhkqcmku1#

我第一次看到背景色时,它就显示出来了。浏览器会缓存页面和内容(包括CSS),有时候强制刷新(Ctrl+Shift+R,或者Ctrl+单击刷新按钮)比正常刷新更有帮助。检查可能会让浏览器重新加载文件。

相关问题