开发者

With CSS, how do you unhighlight a link after clicking a different link?

开发者 https://www.devze.com 2023-01-16 00:26 出处:网络
For example, on a navigation bar, you only want one link to be hightlighted, the one that th开发者_如何学Goe user had most recently clicked. If a user clicks a different link, then the previously high

For example, on a navigation bar, you only want one link to be hightlighted, the one that th开发者_如何学Goe 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?


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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消