gpt4 book ai didi

css - 如何保持:active css style after clicking an element

转载 作者:技术小花猫 更新时间:2023-10-29 10:16:25 45 4
gpt4 key购买 nike

我使用 anchor 作为我的站点导航。

<div id='nav'>
<a href='#abouts'>
<div class='navitem about'>
about
</div>
</a>
<a href='#workss'>
<div class='navitem works'>
works
</div>
</a>
</div>

CSS

#nav {
margin-left: 50px;
margin-top: 50px;
text-transform: uppercase;
}
.navitem {
background: #333;
color: white;
width: 230px;
height: 50px;
font-size: 25px;
line-height: 50px;
padding-left: 20px;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
margin-top: 10px;
}
.about:hover {
background: #cc00ff;
}
.about:active {
background: #ff00ff;
color: #000;
width: 250px;
}
.works:hover {
background: #0066FF;
}
.works:active {
background: #0099cc;
color: #000;
width: 250px;
}

我想知道如何让 div 元素样式在点击后保持 :active 状态一次,直到我点击另一个导航栏元素,那么该怎么做?

最佳答案

结合 JS 和 CSS:

button{
/* 1st state */
}

button:hover{
/* hover state */
}

button:active{
/* click state */
}

button.active{
/* after click state */
}


jQuery('button').click(function(){
jQuery(this).toggleClass('active');
});

关于css - 如何保持:active css style after clicking an element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7738219/

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