HTML 用來建立網頁的結構。此外,CSS 用於設計這些頁面的視覺外觀。在 CSS 中,縮排是網頁上文字格式的重要面向之一。它允許開發人員在段落開頭創建視覺效果。縮排可用於使文字更易於閱讀並在文件中創建結構感。
CSS 中的縮排
CSS 是一個功能強大的工具,可讓開發人員控制網頁上 HTML 元素的視覺呈現。我們可以使用 CSS 設定文字樣式,並更改其字體、大小、顏色,甚至縮排。
在 CSS 中,縮排用於在元素之間建立視覺分隔。它透過在元素的左側或右側添加空間或填充來在元素之間創建視覺分隔。
文法
css selector { text-indent: value; }
使用 Text-Indent 屬性進行首行縮排
CSS 允許開發人員使用 text-indent 屬性縮排段落的第一行。該屬性已設為 0,這表示該屬性上沒有縮排。例如,如果我們想要將網頁上的所有段落縮排 25 像素,我們可以使用以下程式碼 -
p { text-indent: 25px; }
範例 1
以下是為網頁上所有段落設定 25px 縮排的範例。
<!DOCTYPE html> <html> <head> <style> h2 { text-align: center; } p { text-indent: 35px; } </style> </head> <body> <h2 id="This-is-an-example-of-a-text-indent-property">This is an example of a text-indent property</h2> <p>This is the first indented paragraph. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p> <p>This is a second indented paragraph. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p> <p>This is the nth indented paragraph, Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p> </body> </html>
如何縮排第二行段落?
“text-indent”屬性用於縮排段落的第一行。要縮排段落的第二行,首先我們必須刪除第一行的縮排。為此,我們可以使用「text-indent」的負值將第一行向左移動,之後,我們使用「padding-left」的正值將第二行向右移動。例如 -
p { text-indent: -20px; padding-left: 20px; }
在上面的程式碼中,我們將段落的第一行縮排 -20px,這會將其向左移動 -20px,而第二行縮排 20px,這會將其移回右側。
讓我們來看一些使用 CSS 縮排段落第二行的範例。
範例 2
這是一個使用CSS元素設定Paragraph第二行縮排的範例
<!DOCTYPE html> <html> <head> <style> h2 { text-align: center; } p { text-indent: -30px; padding-left: 30px; } </style> </head> <body> <h2 id="Indent-Second-Line-of-Paragraph">Indent Second Line of Paragraph</h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p> </body> </html>
範例 3
以下是使用 CSS 類別選擇器設定段落第二行縮排的範例。
<!DOCTYPE html> <html> <head> <style> h2 { text-align: center; } .indent-p { text-indent: -4em; padding-left: 4em; } </style> </head> <body> <h2 id="Indent-Second-Line-of-Paragraph-using-CSS-class-selector">Indent Second Line of Paragraph using CSS class selector</h2> <p class="indent-p">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p> </body> </html>
結論
在這裡,我們討論了段落第二行的縮排。這是提高網頁可讀性和外觀的簡單方法。透過使用「text-indent」屬性,我們可以創造獨特且具有視覺吸引力的外觀,使內容脫穎而出。
以上是如何使用CSS設定段落第二行縮排?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

SVG具有自己的一套元素,屬性和屬性集,以至於內聯SVG代碼可能會變得漫長而復雜。通過利用CSS和SVG 2規範的一些即將到來的功能,我們可以減少該代碼以進行清潔標記。

PWA(Progressive Web應用程序)已經與我們在一起了一段時間。但是,每次我嘗試向客戶解釋它時,同樣的問題都會出現:“我的用戶會成為


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

WebStorm Mac版
好用的JavaScript開發工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中