如何在HTML中設定文字方向?


direction 屬性指定網頁上塊元素中的文字方向。

我們使用 style 屬性在 HTML 中設定文字方向。style 屬性指定塊內元素的內聯樣式。style 屬性與 CSS 屬性 direction 一起使用來設定文字方向。

語法

以下是使用 CSS 屬性設定文字方向的語法。

以下語法將文字設定為從右到左方向。

<p style = "direction: rtl;">The text…</p>

示例

以下是設定 HTML 文字方向的示例程式。

<!DOCTYPE html> <html> <head> </head> <body> <p style = "direction: rtl;"> Delhi Land and Finance is one of the largest commercial real estate developer in India. </p> </body> </html>

使用 CSS 將文字方向設定為從左到右

我們可以使用以下語法將文字方向設定為從右到左。

語法

以下是使用 CSS 屬性設定文字方向的語法。

以下語法將文字設定為從左到右方向。

<p style = "direction: ltr;">The text…</p>

示例

以下是設定 HTML 文字方向的示例程式。

<!DOCTYPE html> <html> <head> </head> <body> <p style = "direction: ltr;"> Delhi Land and Finance is one of the largest commercial real estate developer in India. </p> </body> </html>

使用 CSS 將文字方向設定為 auto

我們可以使用以下語法將文字方向設定為 auto。

語法

以下是使用 CSS 屬性設定文字方向的語法,瀏覽器會根據網頁內容的方向來確定文字方向。

<p style = "direction: auto;">The text…</p>

示例

以下是設定 HTML 文字方向的示例程式。

<!DOCTYPE html> <html> <head> </head> <body> <p style = "direction: auto;"> Delhi Land and Finance is one of the largest commercial real estate developer in India. </p> </body> </html>

示例

以下是使用內部樣式表在 HTML 中設定文字方向的示例程式。

<!DOCTYPE html> <html> <head> <style> p.id { direction: rtl; } </style> </head> <body> <p class="id"> DLF stands for Delhi Land and FinanceDelhi Land and Finance is one of the largest commercial real estate developer in India. </p> </body> </html>

更新於:2022年11月11日

3K+ 次瀏覽

啟動您的職業生涯

完成課程獲得認證

開始學習
廣告