:target

# 锚的名称是在一个文件中链接到某个元素的URL。元素被链接到目标元素。

:target选择器可用于当前活动的target元素的样式。

 

语法

:target
{
border: 2px solid #D4D4D4;
background-color: #e5eecc;
}

例子

HTML

<h1>This is a heading</h1>

<p><a href="#news1">Jump to New content 1</a></p>
<p><a href="#news2">Jump to New content 2</a></p>

<p>Click on the links above and the :target selector highlight the current active HTML anchor.</p>

<p id="news1"><b>New content 1...</b></p>
<p id="news2"><b>New content 2...</b></p>

<p><b>注意:</b> IE 8 以及更早版本的浏览器不支持 :target 选择器.</p>

CSS

:target
{
	border: 2px solid #D4D4D4;
	background-color: #e5eecc;
}

执行结果

This is a heading

Jump to New content 1

Jump to New content 2

Click on the links above and the :target selector highlight the current active HTML anchor.

New content 1...

New content 2...

注意: IE 8 以及更早版本的浏览器不支持 :target 选择器.

参考

相关页面

外部链接