对于包含大量内容的页面,我最近开始喜欢使用 css :target 来仅显示所需的内容。代码可能如下所示:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test Page</title>
<style type="text/css">
body {font-family:sans-serif;}
#some-content>*,
#some-content>*:target ~ h2:last-of-type,
#some-content>*:target ~ h2:last-of-type+* { display: none; }
#some-content>h2:target,
#some-content>h2:target+*,
#some-content>h2:last-of-type,
#some-content>h2:last-of-type+* { display: block; }
</style>
</head>
<body>
<h1>Test Page</h1>
<ol>
<li><a href="#test-1">First link</a></li>
<li><a href="#test-2">Second link</a></li>
<li><a href="#test-3">Third link</a></li>
<li><a href="#test-4">Fourth link</a></li>
<li><a href="#test-5">Fifth link</a></li>
</ol>
<div id="some-content">
<h2 id="test-1">First header</h2>
<p>First content</p>
<h2 id="test-2">Second header</h2>
<p>Second content</p>
<h2 id="test-3">Third header</h2>
<p>Third content</p>
<h2 id="test-4">Fourth header</h2>
<p>Fourth content</p>
<h2 id="test-5">Fifth header</h2>
<p>Fifth content</p>
</div>
</body>
</html>
我的问题是双重的:
- 现代蜘蛛是否遵循锚链接?
- 如果不是,是否只有最后一个 h2 及其下一个兄弟姐妹会被蜘蛛?