Hướng dẫn how do i create an anchor link in html? - Làm cách nào để tạo liên kết neo trong html?

Liên kết neo là một liên kết, cho phép người dùng chảy qua một trang web. Nó giúp cuộn và đọc lướt dễ dàng. Một mỏ neo có tên có thể được sử dụng để liên kết đến một phần khác của cùng một trang (như nhanh chóng điều hướng) hoặc đến một phần cụ thể của một trang khác.

Hãy cùng xem cách nhảy đến một phần được đánh dấu của trang bằng cách sử dụng thẻ. Nó khá đơn giản!

  1. Thêm một thuộc tính ID vào phần tử neo để đặt tên cho phần của trang. Giá trị của thuộc tính có thể là một từ hoặc một cụm từ (khi sử dụng các cụm từ hãy nhớ không có khoảng trắng, sử dụng dấu gạch ngang hoặc gạch dưới thay vào đó).id attribute to the anchor element to give a name to the section of the page. The value of the attribute may be a word or a phrase (when using phrases remember not to have spaces, use dashes or underscores instead).

The  name where you want to jump

Ngoài ra, bạn cũng có thể có các loại neo sau:

  1. Neo trong tiêu đề: Tên phần

    Section name

  2. neo trong một hình ảnh:
    Hướng dẫn how do i create an anchor link in html? - Làm cách nào để tạo liên kết neo trong html?
  3. Neo trong một đoạn: Tên đoạn văn

    Paragraph name

Hãy nhớ rằng mỗi ID chỉ có thể xuất hiện một lần trên một trang.id can appear only once on a page.

  1. Tạo một siêu liên kết bằng cách sử dụng ID của mục tiêu liên kết, trước #.id of the link target, preceded by #.

Jump to the part of the page with the “anchor-name” id 

Bây giờ, chỉ cần thêm văn bản ưa thích và bạn sẽ có thể bay qua các phần trang.

Ví dụ về việc tạo liên kết neo nhảy:

html>
<html>
  <head>
    <title>Title of the documenttitle>
  head>
  <body>
    <a href="#section-2">Jump to section 2a><br />
    <a href="#section-3">Jump to section 3a><br />
    <a href="#section-4">Jump to section 4a><br />
    <h2 id="section-1">Section 1h2>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
    <h2 id="section-2">Section 2h2>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
<h2 id="section-3">Section 3h2>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
<h2 id="section-4">Section 4h2>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
    <p>Go to the
      <a href="#section-1">topa>.
    p>
  body>
html>

Cũng có thể cung cấp phong cách bổ sung cho neo nhảy. Đối với điều đó, sử dụng một thẻ trong phần tử và tạo kiểu dáng cho phần để được nhảy bằng cách sử dụng các thuộc tính màu và nền.

Ví dụ về kiểu dáng liên kết neo nhảy:

html>
<html>
  <head>
    <title>Title of the documenttitle>
<style>
    h2 {
      color: #1c87c9;
    }
    h2:target {
      color: white;
      background: #1c87c9;
    }
    style>
  head>
  <body>
    <a href="#section-2">Jump to section 2a><br />
    <a href="#section-3">Jump to section 3a><br />
    <a href="#section-4">Jump to section 4a><br />
    <h2 id="section-1">Section 1h2>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
    <h2 id="section-2">Section 2h2>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
<h2 id="section-3">Section 3h2>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
<h2 id="section-4">Section 4h2>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
<p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.
    p>
    <p>Go to the
      <a href="#section-1">topa>.
    p>
  body>
html>

Liên kết đến mỏ neo từ một trang web khác

Bạn cũng có thể liên kết đến liên kết neo của bạn từ các trang web khác. Đối với điều đó, thêm URL theo sau là # và giá trị neo. Có hai loại cách sử dụng như vậy.

Liên kết đến một trang khác trong cùng một miền:

Go to the HTML Links in our website.

Liên kết từ một trang web khác:

Go to the main page of Wikipedia .

Ví dụ về liên kết với neo từ một trang web khác:

html>
<html>
  <head>
    <title>Title of the documenttitle>
  head>
  <body>
    <h2 id="Lorem_Ipsum">Lorem Ipsumh2>
    <p>
      Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    p>
    <p>
      <a href="/learn-html/html-links.html#syntax-2">Go to the HTML Links in our website.a>
    p>
  body>
html>

Bạn có thể tạo trang neo trang trong HTML không?

: Phần tử neo.Phần tử HTML (hoặc phần tử neo), với thuộc tính HREF của nó, tạo ra một siêu liên kết đến các trang web, tệp, địa chỉ email, vị trí trong cùng một trang hoặc bất cứ điều gì khác mà URL có thể giải quyết.Nội dung trong mỗi nội dung sẽ chỉ ra đích của liên kết.The HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address. Content within each should indicate the link's destination.

Thẻ neo liên kết trong HTML là gì?