HTML - content 屬性



HTML content 屬性用於顯示/包含 name 屬性或 HTTP-equiv 屬性的值,具體取決於使用哪個屬性。

此屬性與 <meta> 標籤一起使用,用於設定 HTML 文件中元元素的資訊。HTTP-equiv 屬性用於為 content 屬性的值提供 HTTP 頭。

HTTP-equiv 屬性接受 refresh 作為值。它定義了文件根據 content 屬性值重新整理自身的時間間隔。

語法

<meta content = "text"></meta>

應用於

以下列出的元素允許使用 HTML content 屬性

元素 描述
<meta> HTML <meta> 標籤用於提供此類附加資訊。

HTML content 屬性示例

下面的示例將說明 HTML content 屬性,以及我們應該在哪裡以及如何使用此屬性!

提及 HTML 文件的內容

在下面的示例中,我們使用 meta 標籤的 content 屬性來提及文件的附加資訊。執行以下程式碼後,輸出將在網頁上以專案符號格式顯示列表項。

<!DOCTYPE html>
<html lang="en">
<head>
   <meta content="Enroll course for free">
   <title>HTML 'content' attribute</title>
</head>
<body>
   <!--HTML 'content' attribute-->
   <p>Example of the HTML 'content' attribute</p>
   <h3>Course lists:</h3>
   <ul>
      <li>HTML</li>
      <li>CSS</li>
      <li>JavaScript</li>
      <li>Angular</li>
   </ul>
</body>
</html>

使用 content 屬性重新整理網頁

以下是 HTML ‘content’ 屬性的另一個示例。這裡,‘content’ 屬性用於 <meta> 元素中,以包含 HTTP-equiv 屬性的值。

我們將 ‘refresh’ 字串賦值給 HTTP-equiv 屬性,這將根據時間間隔(即 content 屬性值)重新整理文件。

<!DOCTYPE html>
<html lang="en">
<head>
   <!--content attribute-->
   <meta http-equiv="refresh" content="30">
   <title>HTML 'content' attribute</title>
</head>
<body>
   <!--HTML 'content' attribute-->
   <p>Example of the HTML 'content' attribute</p>
   <h1>Text within the h1 heading...</h1>
</body>
</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
content
html_attributes_reference.htm
廣告
© . All rights reserved.