Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

จัดตำแหน่งข้อความย่อหน้าด้วย CSS (text-indent)


คุณสมบัติ text-indent

เพื่อจัดตำแหน่งข้อความของย่อหน้า ให้ใช้คุณสมบัติ text-indent

ตัวอย่าง

ค่าที่เป็นไปได้: เปอร์เซ็นต์ หรือตัวเลขระบุระยะย่อ ลองรันโค้ดต่อไปนี้เพื่อนำ text-indent ไปใช้กับ CSS:

<html>
  <head>
  </head>
  <body>
    <p style="text-indent:2cm;">
      This text will have first line indented by 2cm and this line will remain at
      its actual position this is done by CSS text-indent property. </p>
  </body>
</html>

รายละเอียด:

  • เฉพาะบรรทัดแรกของย่อหน้าที่จะถูกย่อ
  • ค่าลบได้ (hanging indent)
  • หน่วย: px, em, rem, cm, %, ฯลฯ
  • สืบทอดได้ (inherited)

แก้ไขจากต้นฉบับ: คำว่า "text-index" ผิด ควรเป็น "text-indent"