CSS - 在此示例中将当前活动状态更改为悬停状态

发布于 2024-12-11 20:28:05 字数 558 浏览 0 评论 0原文

我正在研究一些纯 CSS 导航,我正在尝试将当前的“活动”状态更改为悬停状态。我自己并没有完全编写原始代码,对其进行逆向工程有点耗时(原始代码是公共领域)。

在此处输入图像描述

我希望当前的“活动”状态(即 menu2)也< /em> 悬停状态,而不是仅仅将背景颜色更改为更深一些。

您可以在此处查看演示。

您可以在此处下载源代码 或从上面的演示中查看源代码。

ps 我考虑将其发布在网站管理员/程序员/代码审查上,但它似乎并不像这里那么合适,因为这并不是要求对我的代码本身进行审查,而是一个特定的网络而不是一般的网络问题,与编程原理无关...如果我不正确,请随意迁移。 :)

I have some pure CSS navigation I'm working on and I'm trying to get what is currently the "active" state to the hover state. I didn't write the original code entirely myself, and it's been somewhat of a time-consuming process reverse-engineering it (the original code was public domain).

enter image description here

I would like it such that the current "active" state (i.e. menu2) is also the hover state, instead of merely changing the background color to be a bit darker.

You can view a demo here.

You can download the source here or view the source from demo above.

p.s. I considered posting this on webmasters/programmers/code review but it didn't seem quite as appropriate as here, since this isn't asking for a review of my code per se, is a specific rather than a general web question, and is not about programming principles... If I am incorrect, feel free to migrate. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云雾 2024-12-18 20:28:05

这就是你所追求的对吗?

演示

模仿悬停状态触发的活动状态,

关键是这个 css:

#hNav>ul>li:hover {height:52px;margin:0;padding:0}
#hNav>ul>li:hover>span.o1{background:transparent url('http://i.imgur.com/ax6LZ.png') left top no-repeat;display:block;height:52px}
#hNav>ul>li:hover>span a{background:transparent url('http://i.imgur.com/zapF1.png') right top no-repeat;color:#000;padding:22px 0 0}

当然这些是演示网址...根据需要替换。

This is what you're after correct?

Demo

Source

Mimic the active state to be triggered by the hover state

the key was this css:

#hNav>ul>li:hover {height:52px;margin:0;padding:0}
#hNav>ul>li:hover>span.o1{background:transparent url('http://i.imgur.com/ax6LZ.png') left top no-repeat;display:block;height:52px}
#hNav>ul>li:hover>span a{background:transparent url('http://i.imgur.com/zapF1.png') right top no-repeat;color:#000;padding:22px 0 0}

of course those are the demo urls... replace as needed.

塔塔猫 2024-12-18 20:28:05

我不确定这是否是您想要的,但如果您尝试在活动元素上显示悬停的特定样式,您可以通过将 CSS 伪元素链接在一起来实现它,即:

以及 a:hover {background:#EEE } 您可以使用 a:active:hover {background:#EEE } ,它仅适用于悬停事件上的活动元素。

I'm not sure if this is what you're after but if you're trying to display a particular style for Hover over an Active element, you can achieve it by chaining the CSS pseudo elements together, ie:

As well as a:hover { background:#EEE } you can have a:active:hover { background:#EEE } which will only apply to Active Elements on a Hover Event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文