<code class="language-html"><!DOCTYPE html> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Understanding the HTML rel Attribute</title> <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"> </code>
請注意title
>屬性的使用。此文本出現在瀏覽器的樣式表選擇菜單中(如果有的話)。
rel="alternate"
> favicons
<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>指定favicon(網站圖標),使用
rel="shortcut icon"
頁面關係(導航)
<code> <link href="/favicon.ico" rel="shortcut icon"> </code>對於順序頁面,
>
rel="next"
許可rel="prev"
自定義關係rel="license"
本節將回答有關“ rel”屬性的常見問題。
>
rel
>
是的,諸如rel="stylesheet"
>和
rel="nofollow"
>指定文檔的替代版本(例如,不同的語言)。
rel="canonical"
>如何與a tag一起使用的rel屬性?
)。
rel="alternate"
>我可以在rel屬性中使用多個值嗎?
>
<link>
rel =“作者”屬性是什麼? rel="nofollow"
rel="nofollow noopener"
指定網站的favicon。
rel =“ next”和rel =“ prev”?
>之間有什麼區別以上是rel(html屬性)的詳細內容。更多資訊請關注PHP中文網其他相關文章!