如何在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+ 瀏覽量

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告