大家好,欢迎来到freecodecamp HTML专题第10篇。
今天的挑战依然关于a
标签。
a
元素除了可以指向外部的一个网站之外,同样也可以用来跳转到网站内部的某一个区域。这一点大家都应该体会过,当我们看一篇长文博客,我们经常通过点击小标题的方式超链接到文章当中具体的位置。
想要创建一个内部的链接,同样需要使用href
这个属性,我们将它设置成'#'加上具体的id
的形式来实现。这里的id
是HTML当中的一个通用属性,任何标签都可以加上id
。id
作为一个标识符,可以作为CSS样式的设置目标,也可以作为a
标签的跳转目标。需要注意的是对于每一个元素赋予的id
都应该是唯一的。
下面我们展示一个通过id
完成内部跳转的例子:
<a href="#contacts-header">Contacts</a>
...
<h2 id="contacts-header">Contacts</h2>
我们给h2
标签赋予了一个id
属性,当我们点击a
标签的时候,它就会跳转到这个id
标记的区域。
通过修改href
属性的值将网站当中外部的标签修改成内部的标签'#footer',并且把对应的文本从"cat photos"改成"Jump to Bottom"。
移除a
标签中target=_blank
属性,因为它会使得用户在点击链接的时候打开一个新的页面。
之后在<footer>
标签当中加上一个为"footer"的id
属性。
a
标签footer
标签a
标签需要有一个指向"#footer"的href
属性a
标签不能有target
属性a
标签的文本应该为"Jump to Bottom"footer
标签需要有一个为"footer"的id
属性<h2>CatPhotoApp</h2>
<main>
<a href="https://freecatphotoapp.com" target="_blank">cat photos</a>
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff. Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched. Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched. Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff. Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
<p>Meowwww loved it, hated it, loved it, hated it yet spill litter box, scratch at owner, destroy all furniture, especially couch or lay on arms while you're using the keyboard. Missing until dinner time toy mouse squeak roll over. With tail in the air lounge in doorway. Man running from cops stops to pet cats, goes to jail.</p>
<p>Intently stare at the same spot poop in the plant pot but kitten is playing with dead mouse. Get video posted to internet for chasing red dot leave fur on owners clothes meow to be let out and mesmerizing birds leave fur on owners clothes or favor packaging over toy so purr for no reason. Meow to be let out play time intently sniff hand run outside as soon as door open yet destroy couch.</p>
</main>
<footer>Copyright Cat Photo App</footer>
今天的挑战很简单,其实就是按照设置内部跳转的方式来修改一下html代码。主要分为三个步骤,一个步骤是在footer
标签当中加上我们跳转的目标,也就是id
属性。接着在a
标签当中修改跳转的目标,从外部的链接改成内部的id
。最后我们改一下a
标签的文本信息即可。
<h2>CatPhotoApp</h2>
<main>
<a href="#footer">Jump to Bottom</a>
<img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
<p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff. Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched. Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.</p>
<p>Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched. Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff. Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.</p>
<p>Meowwww loved it, hated it, loved it, hated it yet spill litter box, scratch at owner, destroy all furniture, especially couch or lay on arms while you're using the keyboard. Missing until dinner time toy mouse squeak roll over. With tail in the air lounge in doorway. Man running from cops stops to pet cats, goes to jail.</p>
<p>Intently stare at the same spot poop in the plant pot but kitten is playing with dead mouse. Get video posted to internet for chasing red dot leave fur on owners clothes meow to be let out and mesmerizing birds leave fur on owners clothes or favor packaging over toy so purr for no reason. Meow to be let out play time intently sniff hand run outside as soon as door open yet destroy couch.</p>
</main>
<footer id="footer">Copyright Cat Photo App</footer>