使用CSS,如何在单击其他链接后取消突出显示链接? [英] With CSS, how do you unhighlight a link after clicking a different link?

查看:132
本文介绍了使用CSS,如何在单击其他链接后取消突出显示链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在导航栏上,您只需要一个高亮显示的链接,即用户最近点击过的链接。如果用户单击其他链接,则先前突出显示的链接将恢复正常。你如何使用CSS?

For example, on a navigation bar, you only want one link to be hightlighted, the one that the user had most recently clicked. If a user clicks a different link, then the previously highlighted link goes back to normal. How do you do with with CSS?

推荐答案

据我所知,你所要求的是不可能通过使用仅限 CSS。虽然有某些链接状态的CSS伪类(例如a:hover),但是没有CSS选择器(至少在CSS 2.0中没有;可能3.0添加了什么?),它将在当前上应用样式URL。

To my knowledge, what you're asking isn't possible to achieve by using only CSS. While there are CSS pseudo-classes for certain link states (such as "a:hover"), there is no CSS selector (at least not in CSS 2.0; maybe 3.0 added something?) that will apply a style on the "current" URL.

要实现这一点,您必须将CSS与一些用于生成内容的动态方法(例如PHP,CGI或我最喜欢的Python)结合起来。可以在这里找到在PHP中执行此操作的良好指南;您可以从该文章中推断出一般概念,并将其应用于您认为的任何内容生成:

To achieve that, you have to combine CSS along with some dynamic means for generating content (such as PHP, CGI, or my favorite - Python). A good guide for doing this in PHP can be found here; you can deduce the general concept from that article and apply it to any content-generation you feel like:

http://www.alistapart.com/articles/keepingcurrent/

Isaac

这篇关于使用CSS,如何在单击其他链接后取消突出显示链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆