【发布时间】:2021-07-16 21:58:49
【问题描述】:
我曾尝试环顾谷歌和堆栈溢出以了解我的问题发生的原因,不幸的是,这些方法都不起作用。我尝试将!important 元素添加到css,但这也不起作用。我以为这是我对图标的定位,但我尝试了不同的定位,但仍然不起作用。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
code is here and linked to css
</head>
<body>
<div class="pageIcons">
<div class="facebook">
<a href="https://www.facebook.com/jake.stecklow">
<img src="facebook.svg">
</a>
</div>
<div class="instagram">
<a href="https://www.instagram.com/jstecklow08/">
<img src="instagram.svg">
</a>
</div>
<div class="twitter">
<a href="https://twitter.com/JakeStecklow">
<img src="twitter.svg">
</a>
</div>
</div>
</body>
</html>
这是我的 pageIcons 和 Anchor 标签的 CSS。
.pageIcons {
position: fixed;
z-index: 2;
margin-left: 97vw;
margin-top: 40vh;
height: 1.5vh;
width: 1.5vw;
line-height: 30px;
}
a {
fill: #c2c2c2;
}
a:hover {
fill: white;
}
请记住,我已尝试填充 pageIcons 而不是锚 css。
非常感谢您的帮助。
【问题讨论】:
-
fill应该应用于 svg,而不是锚标签 -
所以,
a:hover svg { fill: ... }和a svg { fill: ... }应该可以工作。 -
@RenevanderLende 是否应将
img标签替换为svg标签? -
可能。目前,您的 SVG 被视为图像(阅读:jpg、png),但您想更改该图像的内容(其颜色)。为此,
img必须是svg。这将要求您学习如何将 SVG 合并到您的文档中。没那么难,但是当你有很多小 SVG 时有点麻烦。大多数使用 SVG 图标的页面在主文档中都有这些图标,因此它们可以访问属性。