有时,我们可能需要使用多个不同的#
尾URL来提供指向网页上特定部分的路径,而就我所知,对于这项任务,我们必须使用多个空白<a>
元素.下面是一个例子:
<p><a href="#sun">Lorem</a> ipsum.</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem <a href="#yellow">ipsum</a> dolor sit amet.</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor <a href="#hot">sit</a> amet.</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor sit amet.</p>
<a id="yellow"></a>
<a id="hot"></a>
<h1 id="sun">Sun</h1>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem ipsum dolor sit amet.</p>
在"跳转"之后(即,在用户点击了一个超链接之后),我更愿意使用:target
伪类突出显示<h1>
元素Sun
.
但如何让它不仅适用于href="sun"
,还适用于href="hot"
和href="yellow"
?
/* works for href="sun" */
:target { outline: 1px solid red; }
/* my attempt to make it work for href="hot". Doesn't work.
And there is still a question how to make it work for href="yellow" */
:target + h1 { outline: 1px solid red; }