我正在上响应式网页设计类(class),遇到了一个非常奇怪的问题。我为我的虚假电子商务网站制作的 Logo 无法在 Firefox 中加载,但会在 Chrome 中加载。我的教授有数十年使用 HTML/CSS/JS 的经验,甚至他也无法弄清楚为什么会出现这个问题。我发现如果我将图像的宽度更改为特定数量而不是 100% 在我的 CSS 中,它会起作用。但是为什么在 Chrome 中设置为 100% 而在 Firefox 中却不能正常工作呢?
这是我的 HTML(至少重要的部分,在你问之前,是的,我已经关闭了所有重要的标签,如 body、main、html 等)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Orbitron:500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Cinzel:400,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="display.css" type="text/css">
</head>
<body>
<div id="particles-js"></div>
<script src="javascript/particles.js"></script>
<script src="javascript/app.js"></script>
<header>
<div class="logostuff">
<a id="logoanchor" href="index.html"><img id="logo" src="images/LogoMeta.svg" alt="META website logo"></a>
<a id="cartanchor" href="cart.html"><img id="cartimg" src="images/cart.svg" alt="Cart image"></a>
</div>
<h4 id="tagline">Let the professionals build it for you!</h4>
<nav>
<ul>
<li><a href="about.html">About Us</a></li>
<li style="margin-bottom: 0.3rem;"><a href="merch.html"> </a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
</header>
这是相关的 CSS 位
.logostuff {
justify-content: space-between;
display: flex;
}
.logoanchor {
width: 100%
}
#cartimg {
width: 100%;
max-width: 60px;
}
#cartanchor {
margin-top: 0.9rem;
width: 20%;
max-width: 320px;
}
#logo {
width: 100%;
}
此外,javascript 与此问题无关,因为没有它问题仍然存在。当我在 Firefox 的开发工具中瞄准我的图像时,它说它是 0x0,它应该占用尽可能多的空间,仍然允许我的购物车 SVG 存在于它旁边。
https://imgur.com/a/yBHtdzs这是它在两种浏览器上的外观的 imgur 相册。
编辑 1:这是 Logo 的 SVG https://svgur.com/s/FxL
最佳答案
我使用您提供的 svg 在 chrome 和 firefox 中使用 codepen 尝试了代码。这里的问题是 logoanchor 有一个类选择器而不是 id 选择器。在您的 css 文件中将 .logoanchor
更改为 #logoanchor
。
关于html - 图片在 Chrome 中加载,但在 Firefox 中不加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58719397/