gpt4 book ai didi

css - 添加第二个悬停选择器

转载 作者:行者123 更新时间:2023-11-28 07:58:52 25 4
gpt4 key购买 nike

您好,我已经创建了一个菜单。添加了一个事件类,因此当用户单击菜单图标时,它会突出显示页面链接到的“LI”。

在您登录之前,我已经调用了悬停选择器。已添加 UL 的背景色。

我的问题是,我是否可以在登录时添加第二个悬停选择器并更改 UL 的背景,而无需更改用户登录前设置的属性。

我可以在不添加另一个 css 类的情况下做到这一点吗?像::before 或::after 或 .active:hover 这样的东西。那会成功吗?

.menuColumn #nav ul li a.active {
background: #029EF1;
box-shadow: 0px 3px 0px #0175B2;
color: #FFF;
}
.menuColumn #nav ul {
list-style-type: none;
margin: 0;
padding: 0;
background: #E6E7E9;
}

JsFiddle Demo

片段演示:

 .example1 {
width: 20%;
}
.example1 #nav ul {
list-style-type: none;
margin: 0;
padding: 0;
background: #E6E7E9;
}
.example1 #nav ul li {
list-style: none;
display: block;
position: relative;
text-align: left;
border-bottom: 1px solid #CDCED0;
}
.example1 #nav ul li:last-child {
border-bottom: none;
}
.example1 #nav ul li a {
text-decoration: none;
color: #7E7F81;
line-height: 3em;
display: block;
padding-left: 15‌​px;
font-weight: bold;
}
.example1 #nav ul li a:hover {
background: #7E7F81;
color: #FFF;
box-shadow: 0px 3px 0px #DBDCDD;
}
.example1 #nav ul li a.active {
background: #029EF1;
box-shadow: 0px 3px 0px #0175B2;
color: #FFF;
}
.example1 #nav ul li a:not(.active) {
background: #000;
box-shadow: 0px 3px 0px #0175B2;
color: #FFF;
}
<body>
<div class="example1">
<div id="nav" style="padding-top: 4em;">
<ul>
<li><a href="test.html" target="_self" title="#">Example 1</a>
</li>
<li><a href="#" target="_self" title="#">Example 1</a>
</li>
<li><a href="#" target="_self" title="#">Example 1</a>
</li>
</ul>
</div>
</div>
</body>

最佳答案

当涉及包含 .active 类的 ul 时,您将不得不使用一些 javascript 来更改 ULs 背景:

The FIDDLE

$(".active").parents("ul").css( "background" , "yellow" );
 .example1 {
width: 20%;
}
.example1 #nav ul {
list-style-type:none;
margin:0;
padding:0;
background:#E6E7E9;
}
.example1 #nav ul li {
list-style: none;
display: block;
position: relative;
text-align: left;
border-bottom:1px solid #CDCED0;
}
.example1 #nav ul li:last-child {
border-bottom:none;
}
.example1 #nav ul li a {
text-decoration:none;
color:#7E7F81;
line-height:3em;
display:block;
padding-left:15‌px;
font-weight:bold;
}
.example1 #nav ul li a:hover {
background:#7E7F81;
color:#FFF;
box-shadow:0px 3px 0px #DBDCDD;
}
.example1 #nav ul li a.active {
background:#029EF1;
box-shadow:0px 3px 0px #0175B2;
color:#FFF;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div class="example1">
<div id="nav" style="padding-top: 4em;">
<p>UL with .active-link in it:</p>
<ul>
<li><a href="#" target="_self" title="#">Example 1</a></li>
<li><a href="test.html" target="_self" title="#" class="active">Active class</a></li>
<li><a href="#" target="_self" title="#">Example 1</a></li>
<li><a href="#" target="_self" title="#">Example 1</a></li>
</ul>
<p>UL without .active-link in it:</p>
<ul>
<li><a href="#" target="_self" title="#">Example 1</a></li>
<li><a href="test.html" target="_self" title="#">Example 1</a></li>
<li><a href="#" target="_self" title="#">Example 1</a></li>
<li><a href="#" target="_self" title="#">Example 1</a></li>
</ul>
</div>
</div>
</body>

关于css - 添加第二个悬停选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29937567/

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