<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Understanding the HTML rel Attribute</title> </head> <body> <h1>The `rel` Attribute: Defining Relationships in HTML</h1> <p>The <code>rel</code> attribute specifies the relationship between the current document and the linked resource. It's primarily used with the <code><link></code> and <code><a></code> tags to provide context and meaning to links.</p> <h2>Common Uses of the `rel` Attribute</h2> <h3>Stylesheets</h3> <p>The most common use is linking stylesheets: <code><link rel="stylesheet" href="styles.css"></code>. This clearly indicates the linked file is a stylesheet.</p> <h3>Alternate Stylesheets</h3> <p>You can define multiple stylesheets using <code>rel="alternate stylesheet"</code>. However, browser support for easily switching between these is limited. A JavaScript-based solution is often necessary for user selection.</p> <pre class="brush:php;toolbar:false"><code> <link href="main.css" media="screen" rel="stylesheet" type="text/css"> <link rel="alternate stylesheet" title="Higher Contrast" href="contrast.css" type="text/css" media="screen"> <link rel="alternate stylesheet" title="Gratuitous CSS" href="hot.css" type="text/css" media="screen">
Perhatikan penggunaan atribut title
. Teks ini muncul dalam menu pemilihan lembaran gaya penyemak imbas (di mana tersedia).
atribut rel="alternate"
juga digunakan untuk menghubungkan ke format kandungan alternatif seperti RSS atau suapan atom:
<code> <link rel="alternate" type="application/rss+xml" href="/rss.xml" title="RSS 2.0"> <link rel="alternate" type="application/atom+xml" href="/atom.xml" title="Atom 1.0"> </code>
untuk menentukan favicon (ikon laman web), gunakan rel="shortcut icon"
:
<code> <link href="/favicon.ico" rel="shortcut icon"> </code>
untuk halaman berurutan, rel="next"
dan rel="prev"
menentukan halaman seterusnya dan sebelumnya dalam siri.
dan memberikan pautan ke butiran lesen. rel="license"
Hubungan tersuai
Soalan Lazim
Apakah tujuan atribut HTML REL?
Atribut
rel
bagaimana atribut REL berfungsi dengan stylesheets?
rel="stylesheet"
Bolehkah atribut REL digunakan untuk tujuan SEO?
mempengaruhi tingkah laku enjin carian. rel="nofollow"
rel="canonical"
apa atribut rel = "alternatif"?
rel="alternate"
Bagaimana atribut REL digunakan dengan tag?
<link>
Bolehkah saya menggunakan pelbagai nilai dalam atribut Rel? rel="nofollow"
rel="nofollow noopener"
Menentukan pengarang dokumen (walaupun sokongannya terhad).
Menentukan favicon untuk laman web.
Menentukan sumber yang akan dimuat terlebih dahulu untuk meningkatkan prestasi laman web.
Mereka menentukan halaman seterusnya dan sebelumnya dalam urutan kandungan paginated.
Atas ialah kandungan terperinci REL (atribut HTML). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!