CSS-当id链接到使用锚点时突出显示div? [英] CSS- Highlight a div when the id is linked to using an anchor?

查看:168
本文介绍了CSS-当id链接到使用锚点时突出显示div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做的是突出显示具有某个ID的div,当它被另一个页面上的锚点引用时:

What I am attempting to do is to highlight a div with a certain id, when It has been referred to by an anchor on another page IE:

用户点击链接 href =qw.html#test,当页面加载时,带有 id =test
突出显示,以便用户可以清楚地看到它。

User clicks link href="qw.html#test", when the page is loaded, then the div with the id="test" is highlighted so that the user can see it clearly.

我确信我看到一个CSS3示例,如果它链接到。
或者是JavaScript?

I'm sure that I've seen a CSS3 example where a div is highlighted if it was linked to. Or was it JavaScript?

推荐答案

您需要使用:target pseudo-class:

You need to use the :target pseudo-class:

:target {
   background-color: #ffa;
}

JS Fiddle demo

这篇关于CSS-当id链接到使用锚点时突出显示div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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