Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Sử dụng thuộc tính text-transform trong CSS

text-transform kiểm soát viết hoa/chữ thường của văn bản không thay đổi nội dung DOM (chỉ ảnh hưởng hiển thị).

Giá trị

Giá trịHiệu ứngVí dụ input → output
none (mặc định)Giữ nguyên"Hello World" → "Hello World"
capitalizeViết hoa chữ cái đầu từ"hello world" → "Hello World"
uppercaseViết hoa tất cả"Hello World" → "HELLO WORLD"
lowercaseViết thường tất cả"Hello World" → "hello world"
full-widthChuyển sang full-width (CJK)Dùng cho typography CJK
full-size-kanaKana full-size (Japanese)Typography Japanese

Ví dụ

<html>
  <head></head>
  <body>
    <p style="text-transform: capitalize;">This will be capitalized</p>
    <p style="text-transform: uppercase;">This will be in uppercase</p>
    <p style="text-transform: lowercase;">This will be in lowercase</p>
  </body>
</html>

Lưu ý

  • capitalize chỉ viết hoa ký tự đầu của **từ** (tách bởi space, punctuation). Không xử lý đúng mọi ngôn ngữ (ví dụ "iPhone" → "Iphone").
  • Không ảnh hưởng đến element.textContent hoặc value của input (chỉ hiển thị).
  • Kết hợp ::first-letter, ::first-line cho hiệu ứng typography nâng cao.