ข้ามไปที่เนื้อหาหลัก ข้ามไปที่การนำทางเอกสาร
in English

ข้อความ

เอกสารประกอบและตัวอย่างสำหรับยูทิลิตี้ข้อความทั่วไปเพื่อควบคุมการจัดแนว การตัดคำ น้ำหนัก และอื่นๆ

การจัดตำแหน่งข้อความ

ปรับข้อความใหม่เป็นส่วนประกอบได้อย่างง่ายดายด้วยคลาสการจัดตำแหน่งข้อความ สำหรับการจัดตำแหน่งเริ่มต้น สิ้นสุด และกึ่งกลาง มีคลาสแบบตอบสนองที่ใช้เบรกพอยต์ความกว้างของวิวพอร์ตเดียวกันกับระบบกริด

เริ่มการจัดแนวข้อความบนขนาดวิวพอร์ตทั้งหมด

ข้อความที่จัดกึ่งกลางบนวิวพอร์ตทุกขนาด

สิ้นสุดข้อความที่จัดชิดขอบบนวิวพอร์ตทุกขนาด

เริ่มการจัดแนวข้อความบนวิวพอร์ตขนาด SM (เล็ก) หรือกว้างกว่า

เริ่มการจัดแนวข้อความบนวิวพอร์ตขนาด MD (กลาง) หรือกว้างกว่า

เริ่มการจัดแนวข้อความบนวิวพอร์ตขนาด LG (ใหญ่) หรือกว้างกว่า

เริ่มการจัดแนวข้อความบนวิวพอร์ตขนาด XL (ใหญ่พิเศษ) หรือกว้างกว่า

<p class="text-start">Start aligned text on all viewport sizes.</p>
<p class="text-center">Center aligned text on all viewport sizes.</p>
<p class="text-end">End aligned text on all viewport sizes.</p>

<p class="text-sm-start">Start aligned text on viewports sized SM (small) or wider.</p>
<p class="text-md-start">Start aligned text on viewports sized MD (medium) or wider.</p>
<p class="text-lg-start">Start aligned text on viewports sized LG (large) or wider.</p>
<p class="text-xl-start">Start aligned text on viewports sized XL (extra-large) or wider.</p>
โปรดทราบว่าเราไม่มีค��าสยูทิลิตี้สำหรับข้อความที่จัดชิดขอบ แม้ว่าข้อความที่มีความสวยงามและเหมาะสมอาจดูน่าดึงดูดกว่า แต่ก็ทำให้การเว้นวรรคระหว่างคำเป็นแบบสุ่มมากขึ้น ดังนั้นจึงอ่านยากขึ้น

การตัดข้อความและล้น

ตัดข้อความด้วย.text-wrapชั้นเรียน

ข้อความนี้ควรตัด
<div class="badge bg-primary text-wrap" style="width: 6rem;">
  This text should wrap.
</div>

ป้องกันไม่ให้ห่อข้อความด้วย.text-nowrapคลาส

ข้อความนี้ควรล้นพาเรนต์
<div class="text-nowrap bd-highlight" style="width: 8rem;">
  This text should overflow the parent.
</div>

ตัวแบ่งคำ

ป้องกันสตริงข้อความยาวๆ ไม่ให้ทำลายเลย์เอาต์ของส่วนประกอบโดยใช้.text-breakto set word-wrap: break-wordและword-break: break-word. เราใช้word-wrapแทนการoverflow-wrapรองรับเบราว์เซอร์ที่กว้างขึ้น และเพิ่มการเลิกใช้งานword-break: break-wordเพื่อหลีกเลี่ยงปัญหากับคอนเทนเนอร์แบบยืดหยุ่น

mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

<p class="text-break">mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm</p>
โปรดทราบว่า ไม่สามารถใช้คำแตกในภาษาอาหรับซึ่งเป็นภาษา RTL ที่ใช้มากที่สุด ดังนั้น .text-breakจะถูกลบออกจาก CSS ที่คอมไพล์ RTL ของเรา

การแปลงข้อความ

แปลงข้อความในส่วนประกอบด้วยคลาสการใช้อักษรตัวพิมพ์ใหญ่

ข้อความตัวพิมพ์เล็ก

ข้อความตัวพิมพ์ใหญ่

ข้อความ CapiTaliZed

<p class="text-lowercase">Lowercased text.</p>
<p class="text-uppercase">Uppercased text.</p>
<p class="text-capitalize">CapiTaliZed text.</p>

สังเกตว่า.text-capitalizeเปลี่ยนเฉพาะอักษรตัวแรกของแต่ละคำ โดยไม่กระทบกับตัวพิมพ์ของตัวอักษรอื่นๆ

ขนาดตัวอักษร

เปลี่ยนfont-sizeข้อความ อย่างรวดเร็ว ในขณะที่คลาสหัวเรื่องของเรา (เช่น.h1.h6) ใช้font-size, font-weight, และline-heightยูทิลิตี้เหล่านี้ใช้ได้เฉพาะ font-sizeขนาดของยูทิลิตี้เหล่านี้ตรงกับองค์ประกอบส่วนหัวของ HTML ดังนั้นเมื่อจำนวนเพิ่มขึ้น ขนาดจะลดลง

.fs-1 ข้อความ

.fs-2 ข้อความ

.fs-3 ข้อความ

.fs-4 ข้อความ

.fs-5 ข้อความ

.fs-6 ข้อความ

<p class="fs-1">.fs-1 text</p>
<p class="fs-2">.fs-2 text</p>
<p class="fs-3">.fs-3 text</p>
<p class="fs-4">.fs-4 text</p>
<p class="fs-5">.fs-5 text</p>
<p class="fs-6">.fs-6 text</p>

ปรับแต่งข้อมูลที่มีอยู่ของคุณfont-sizeโดยแก้ไข$font-sizesแผนที่ Sass

น้ำหนักแบบอักษรและตัวเอียง

เปลี่ยนfont-weightหรือfont-styleข้อความอย่างรวดเร็วด้วยยูทิลิตี้เหล่านี้ font-styleโปรแกรมอรรถประโยชน์มีตัวย่อ.fst-*และfont-weightโปรแกรมอรรถประโยชน์มีตัวย่อ.fw-*ว่า

ข้อความตัวหนา

ข้อความแสดงน้ำหนักที่ชัดเจนยิ่งขึ้น (สัมพันธ์กับองค์ประกอบหลัก)

ข้อความน้ำหนักปกติ

ข้อความที่มีน้ำหนักเบา

ข้อความน้ำหนักเบา (สัมพันธ์กับองค์ประกอบหลัก)

ข้อความตัวเอียง

ข้อความที่มีรูปแบบตัวอักษรปกติ

<p class="fw-bold">Bold text.</p>
<p class="fw-bolder">Bolder weight text (relative to the parent element).</p>
<p class="fw-normal">Normal weight text.</p>
<p class="fw-light">Light weight text.</p>
<p class="fw-lighter">Lighter weight text (relative to the parent element).</p>
<p class="fst-italic">Italic text.</p>
<p class="fst-normal">Text with normal font style</p>

ความสูงของเส้น

เปลี่ยนความสูงของบรรทัดด้วย.lh-*ยูทิลิตี้

นี่เป็นย่อหน้ายาวที่เขียนขึ้นเพื่อแสดงให้เห็นว่าความสูงของบรรทัดขององค์ประกอบได้รับผลกระทบจากยูทิลิตี้ของเราอย่างไร คลาสถูกนำไปใช้กับองค์ประกอบเองหรือบางครั้งองค์ประกอบหลัก คลาสเหล่านี้สามารถปรับแต่งได้ตามต้องการด้วยยูทิลิตี้ API ของเรา

นี่เป็นย่อหน้ายาวที่เขียนขึ้นเพื่อแสดงให้เห็นว่าความสูงของบรรทัดขององค์ประกอบได้รับผลกระทบจากยูทิลิตี้ของเราอย่างไร คลาสถูกนำไปใช้กับองค์ประกอบเองหรือบางครั้งองค์ประกอบหลัก คลาสเหล่านี้สามารถปรับแต่งได้ตามต้องการด้วยยูทิลิตี้ API ของเรา

นี่เป็นย่อหน้ายาวที่เขียนขึ้นเพื่อแสดงให้เห็นว่าความสูงของบรรทัดขององค์ประกอบได้รับผลกระทบจากยูทิลิตี้ของเราอย่างไร คลาสถูกนำไปใช้กับองค์ประกอบเองหรือบางครั้งองค์ประกอบหลัก คลาสเหล่านี้สามารถปรับแต่งได้ตามต้องการด้วยยูทิลิตี้ API ของเรา

นี่เป็นย่อหน้ายาวที่เขียนขึ้นเพื่อแสดงให้เห็นว่าความสูงของบรรทัดขององค์ประกอบได้รับผลกระทบจากยูทิลิตี้ของเราอย่างไร คลาสถูกนำไปใช้กับองค์ประกอบเองหรือบางครั้งองค์ประกอบหลัก คลาสเหล่านี้สามารถปรับแต่งได้ตามต้องการด้วยยูทิลิตี้ API ของเรา

<p class="lh-1">This is a long paragraph written to show how the line-height of an element is affected by our utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with our utility API.</p>
<p class="lh-sm">This is a long paragraph written to show how the line-height of an element is affected by our utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with our utility API.</p>
<p class="lh-base">This is a long paragraph written to show how the line-height of an element is affected by our utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with our utility API.</p>
<p class="lh-lg">This is a long paragraph written to show how the line-height of an element is affected by our utilities. Classes are applied to the element itself or sometimes the parent element. These classes can be customized as needed with our utility API.</p>

โมโนสเปซ

เปลี่ยนการเลือกเป็นแบบอักษร monospace ของเราด้วย.font-monospace.

นี่อยู่ในโมโนสเปซ

<p class="font-monospace">This is in monospace</p>

รีเซ็ตสี

รีเซ็ตสีของข้อความหรือลิงก์ด้วย.text-resetเพื่อให้รับสีมาจากพาเรนต์

ข้อความปิดเสียงพร้อมลิงก์รีเซ็ต

<p class="text-muted">
  Muted text with a <a href="#" class="text-reset">reset link</a>.
</p>

ตกแต่งข้อความ

ตกแต่งข้อความในส่วนประกอบด้วยคลาสการตกแต่งข้อความ

ข้อความนี้มีบรรทัดด้านล่าง

ข้อความนี้มีเส้นตัดผ่าน

ลิงก์นี้มีการนำการตกแต่งข้อความออก
<p class="text-decoration-underline">This text has a line underneath it.</p>
<p class="text-decoration-line-through">This text has a line going through it.</p>
<a href="#" class="text-decoration-none">This link has its text decoration removed</a>

ซาส

ตัวแปร

// stylelint-disable value-keyword-case
$font-family-sans-serif:      system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
$font-family-monospace:       SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
// stylelint-enable value-keyword-case
$font-family-base:            var(--#{$variable-prefix}font-sans-serif);
$font-family-code:            var(--#{$variable-prefix}font-monospace);

// $font-size-root affects the value of `rem`, which is used for as well font sizes, paddings, and margins
// $font-size-base affects the font size of the body text
$font-size-root:              null;
$font-size-base:              1rem; // Assumes the browser default, typically `16px`
$font-size-sm:                $font-size-base * .875;
$font-size-lg:                $font-size-base * 1.25;

$font-weight-lighter:         lighter;
$font-weight-light:           300;
$font-weight-normal:          400;
$font-weight-bold:            700;
$font-weight-bolder:          bolder;

$font-weight-base:            $font-weight-normal;

$line-height-base:            1.5;
$line-height-sm:              1.25;
$line-height-lg:              2;

$h1-font-size:                $font-size-base * 2.5;
$h2-font-size:                $font-size-base * 2;
$h3-font-size:                $font-size-base * 1.75;
$h4-font-size:                $font-size-base * 1.5;
$h5-font-size:                $font-size-base * 1.25;
$h6-font-size:                $font-size-base;

แผนที่

ยูทิลิตี้ขนาดฟอนต์ถูกสร้างขึ้นจากแผนที่นี้ ร่วมกับ API ยูทิลิตี้ของเรา

$font-sizes: (
  1: $h1-font-size,
  2: $h2-font-size,
  3: $h3-font-size,
  4: $h4-font-size,
  5: $h5-font-size,
  6: $h6-font-size
);

ยูทิลิตี้ API

ยูทิลิตี้แบบอักษรและข้อความได้รับการประกาศในยูทิลิตี้ API ของเราในscss/_utilities.scss. เรียนรู้วิธีใช้ยูทิลิตี้ API

    "font-family": (
      property: font-family,
      class: font,
      values: (monospace: var(--#{$variable-prefix}font-monospace))
    ),
    "font-size": (
      rfs: true,
      property: font-size,
      class: fs,
      values: $font-sizes
    ),
    "font-style": (
      property: font-style,
      class: fst,
      values: italic normal
    ),
    "font-weight": (
      property: font-weight,
      class: fw,
      values: (
        light: $font-weight-light,
        lighter: $font-weight-lighter,
        normal: $font-weight-normal,
        bold: $font-weight-bold,
        bolder: $font-weight-bolder
      )
    ),
    "line-height": (
      property: line-height,
      class: lh,
      values: (
        1: 1,
        sm: $line-height-sm,
        base: $line-height-base,
        lg: $line-height-lg,
      )
    ),
    "text-align": (
      responsive: true,
      property: text-align,
      class: text,
      values: (
        start: left,
        end: right,
        center: center,
      )
    ),
    "text-decoration": (
      property: text-decoration,
      values: none underline line-through
    ),
    "text-transform": (
      property: text-transform,
      class: text,
      values: lowercase uppercase capitalize
    ),
    "white-space": (
      property: white-space,
      class: text,
      values: (
        wrap: normal,
        nowrap: nowrap,
      )
    ),
    "word-wrap": (
      property: word-wrap word-break,
      class: text,
      values: (break: break-word),
      rtl: false
    ),