在 HTML 中建立斜體文字


在 HTML 中,可以使用 <i> 標籤將文字表示為斜體。<i> 標籤開頭和結尾之間的文字將以斜體格式顯示。<i> 標籤被稱為慣用文字元素。

語法

下面顯示了 <i> 標籤在 HTML 中的用法:

<html>
<body>
   <p> Hello Welcome to <i>My World</i></p>
</body>
</html>

在上面的語法中,<i> 開頭和結尾標籤之間的句子將以斜體格式顯示。

Hello Welcome to My World.

如果我們想要表示與周圍環境不同的語言的短語,我們可以在 <i> 標籤內使用 lang 屬性。<i> 標籤不用於樣式目的。透過使用 CSS 的 font-style 屬性,我們可以將文字設定為斜體樣式。

示例

讓我們看看 HTML 中 <i> 標籤的一個示例:

<!DOCTYPE html>
<html>
<head>
   <style>
      i {
         font-style: italic;
      }
   </style>
</head>
<body>
   <p>The Italic element is displayed like this:</p>
   <i>Welcome to My World</i>
   <p>If you want to see the effects, Change the default CSS settings .</p>
</body>
</html>

示例

以下是另一個示例,演示了在頭部部分使用 <i> 標籤:

<!DOCTYPE html>
<html>
<head>
   <h1>TutorialsPoint WebSite</h1>
   <h2>
      <i> www.tutorialspoint.com</i>
   </h2>
</head>
<body>
   <p>The Italic element is displayed in the Head section of HTML document</p>
</body>
</html>

<em> 標籤

為了在 HTML 中強調文字內容,我們使用 <em> 標籤。它與 <italic> 標籤相同。<em> 標籤的開頭和結尾標籤之間的文字將以斜體形式顯示。

斜體 <i> 和強調標籤 <em> 之間的主要區別在於,強調標籤在語義上強調單詞的一部分,而 <i> 標籤則以斜體顯示文字,表示不同的語氣。<em> 標籤的效果可以透過使用 CSS 屬性來實現。

語法

以下是 CSS 中 <em> 標籤的用法:

em {
   font-style: italic;
}
  • <em> 標籤支援全域性屬性和事件屬性。

  • <em> 元素放置在 <body> 標籤內。

  • 它用於將文字與其餘內容隔開。

  • 我們還可以透過應用 CSS 來更改 <em> 標籤的行為。

  • <em> 屬性不儲存值。

  • 所有瀏覽器都支援 <em> 標籤。

現在讓我們看一個程式,演示了在 HTML 中使用強調和斜體標籤:

示例

在這個例子中,我們嘗試一起使用 <em> 和 <i> 標籤:

<!DOCTYPE html>
<html>
<head>
   <style>
      em {
         font-style: italic;
         background-color: yellow;
         text-emphasis-color: green;
         text-emphasis-style: "*";
      }

      i {
         font-style: italic;
         background-color: pink;
      }
   </style>
</head>
<body>
   <p>An Emphasized element and italic text can be displayed like this:</p>
   <em>HTML Tutorial</em>
   <br>
   <br>
   <i>Best Tutorial WebSite</i>
   <p>To see the effects, Change the default CSS settings .</p>
</body>
</html>

更新於: 2023年10月10日

525 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告

© . All rights reserved.