锚点实现网页跳转

 

你可以用a锚点(Anchor,简写 a)来实现网页间的跳转。

锚点需要一个href属性指向目的地,它还需要有锚点文本,例如:

<a href="https://freecodecamp.one">传送至 freecodecamp.one</a>

然后你的浏览器会显示一个可以点击的文本,点击该文本就会跳转到https://freecodecamp.one

 

用锚点实现网页内部跳转

设置锚点的href属性值为井号#加上想跳转区域对应的id属性值,这样就可以创建一个内部跳转。id是用来描述网页元素的一个属性,它的值在整个页面中唯一。

<a href="#contacts-header">Contacts</a>
...
<h2 id="contacts-header">Contacts</h2>

<a href="#footer">Jump to Bottom</a>
 
<footer id="footer">Copyright Cat Photo App</footer>

<a href="地址">可以被点击的文字</a>  <a>跳转文本</a>  href 是目的地

 

<a href="#跳转到这里"></a>

<h2 id="跳转到这里"></h2>

href属性值为#名字

id要等于属性值的名字

posted @ 2021-04-29 10:39  Sai佐为  阅读(467)  评论(0)    收藏  举报