gpt4 book ai didi

css:仅当链接在特定类中时才对链接执行特定操作

转载 作者:太空宇宙 更新时间:2023-11-03 23:21:44 24 4
gpt4 key购买 nike

我很难理解如何在 CSS 中完成这个简单的任务。

这是基本的 HTML 代码:

<div class="menu">
<div class="menuItem uno"><a href="/one.php">1<span>One</span></a></div>
<div class="menuItem dos"><a href="/two.php">2<span>Two</span></a></div>
</div>

我正在尝试更改 a:(超链接)的 css 格式,但只有当它们位于此 menu 类中时,才能这样:

a {
color: #000000;
text-decoration: none;
}

被绕过。

我的 css 文件中有一个 .menu:

.menu {
position: fixed;
padding-top: 15px;
etc...
}

然后我有

.menu a:active, a:hover, a:link, a:visited {
outline: 0;
color: #fff;
text-decoration: none;
}

这对我的 menu 类内部的链接没有任何作用,但它会影响此 menu div 之外的超链接。我的格式有什么问题吗?

最佳答案

您每次都需要指定整个选择器。

.menu a:active,
.menu a:hover,
.menu a:link,
.menu a:visited {
outline: 0;
color: #fff;
text-decoration: none;
}

如果您使用的是 CSS 预处理器,例如 LESS ,你可以嵌套选择器:

.menu {
a:hover,
a:link,
a:active,
a:visited {
outline: 0;
color: #fff;
text-decoration: none;
}
}

关于css:仅当链接在特定类中时才对链接执行特定操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28417873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com