我创建了两个简单的 html 页面,其中一个包含 iframe,第二个加载到第一页的 iframe 中。第一页位于http://quatorze.atspace.co.uk/Webdev/shared/ffbug1.html
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>:target bug in firefox</title>
<style type=text/css>
iframe:target {
display: none;
}
ol {
max-width: 480px;
font-family: sans-serif;
}
li {
margin: 8px;
}
span {
color: red;
}
</style>
</head>
<body>
<div id="div0">
<p><a href="#if">HIDE</a> <a href="#div0">SHOW</a></p>
<iframe id="if" src="ffbug_files/ffbug3.html" width="400" height="200"></iframe>
<ol>In Firefox click links on this page in following order:
<li>Click "DIV 1". First div gets targeted and its background turns silver;</li>
<li>Click "HIDE". Iframe gets targeted and its "display" property is set to "none";</li>
<li>Click "SHOW". Iframe is no longer targeted and its "display" property is reset to "inline";</li>
<li>Now click "DIV 2". Second div gets targeted and its background turns silver. First div is no longer targeted and its "background-color" must be reset to "skyblue" but <span>it remains silver</span>;</li>
<li>Click "DIV 1". First div gets targeted, its background <span>was already silver</span>, second div is no longer targeted and its "background-color" is reset to "skyblue".</li>
<li>Click "DIV 2". Second div gets targeted, its background turns silver, first div is no longer targeted, its "background-color" is reset to "skyblue".</li>
<li>Click "HIDE". Iframe gets targeted and its "display" property is set to "none";</li>
<li>Click "SHOW". Iframe is no longer targeted and its "display" property is reset to "inline";</li>
<li>Now click "DIV 1". First div gets targeted, its background turns silver. Second div is no longer targeted and its "background-color" must be reset to "skyblue", but <span>it remains silver</span>.
</ol>
</div>
</body>
</html>
在 iframe 中加载的第二页位于http://quatorze.atspace.co.uk/Webdev/shared/ffbug_files/ffbug3.html
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>:target bug in firefox</title>
<style type=text/css>
div {
width: 140px;
height: 140px;
border: 2px solid;
margin: 6px;
padding: 10px;
background-color: skyblue;
float: left;
}
div:target {
background-color: silver;
}
</style>
</head>
<body>
<div id="div1"><a href="#div1">DIV 1</a></div>
<div id="div2"><a href="#div2">DIV 2</a></div>
</body>
</html>
如您所见,第一页上有两个链接,分别名为“SHOW”和“HIDE”。
“SHOW”是指包含 div,“HIDE”是指 iframe。
当 iframe 被定位时,它的“display”属性设置为“none”。
在 iframe 中加载的第二页包含两个 div。每个 div 内部都有一个指向该 div 的链接。
每个 div 上设置的 CSS 规则使其在目标从“天蓝色”变为“银色”时更改其背景颜色。
在 Firefox 中,尝试按以下顺序单击第一页上的链接:
单击“DIV 1”。第一个 div 被定位,它的背景变成银色;
单击“隐藏”。iframe 被定位并且其“显示”属性设置为“无”;
点击“显示”。iframe 不再被定位,其“display”属性被重置为“inline”;
现在单击“DIV 2”。第二个 div 成为目标,其背景变为银色。第一个 div 不再是目标,它的“背景颜色”必须重置为“天蓝色”(这就是 Chrome 中实际发生的情况),但它仍然是银色。