gpt4 book ai didi

javascript - 如何为当前页面链接应用CSS样式

转载 作者:太空宇宙 更新时间:2023-11-04 15:35:10 26 4
gpt4 key购买 nike

这是我的代码:

如何为当前页面链接应用一个类,以便鼠标光标将使用默认光标而不是手?

我不想在所有悬停时都使用默认光标。我想将一个类应用于事件列表项,然后使用默认光标(即“主页”index.html)在主页上使用默认光标作为主页。谢谢!

最佳答案

Here's a demo


首先,您需要为每个页面“标识正文”,以区分您所在的页面。

//when at home page

<body id="home"> //or services or contact
<ul id="navigation">
<li class="home">
<a> and so on...
<li class="services">
<a> and so on...

然后,您需要为“当前”页面添加类。

//if literally spoken, it's "when at 'this' page, style the link with 'this' class"

#home .home, //style the home link as "current" when body ID is "home"
#services .services, //style services link as "current" when body ID is "services"
#contact .contact { //style contact link as "current" when body ID is "contact"
//styles when current
}

关于javascript - 如何为当前页面链接应用CSS样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9755083/

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