开发者

how to apply styling on the parent container of a:visited?

开发者 https://www.devze.com 2023-04-06 22:53 出处:网络
I need to style my divs(that\'re pare开发者_StackOverflow社区nt container of links) differently when the links have been visited. Can I do that using pure CSS, or I need to resort to JS ?You can not d

I need to style my divs(that're pare开发者_StackOverflow社区nt container of links) differently when the links have been visited. Can I do that using pure CSS, or I need to resort to JS ?


You can not do this using pure CSS, not even in the latest CSS3 specification. You can do it with JS. With plain JS its quite unpleasant thing to do. If you use let's say jQuery, then you can do something like this:

$('a:visited').parent('div').css('color: #fff;');


No, you can't do backreferences like this in CSS. You'll need to select them using JavaScript.

Alternately, HTML5 allows you to put <a> elements around block elements so you can turn this inside out:

a:visited .parent_container { background: pink; }


It's not possible using only CSS. You've to implement your :visited logic.

Then using JS, when the user click on a link, add a class (ie visited) to its parent div.

0

精彩评论

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