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

Thuộc tính fontVariant trong HTML DOM Style


Giới thiệu

Thuộc tính fontVariant trong HTML DOM Style dùng để thiết lập hoặc lấy việc font có được chuyển thành chữ in hoa nhỏ (small-caps) hay không. Trong small-caps, các chữ thường được chuyển thành chữ hoa nhưng kích thước vẫn bằng chữ thường. Chữ hoa gốc không bị ảnh hưởng.

Cú pháp

Thiết lập fontVariant:

object.style.fontVariant = "normal|small-caps|initial|inherit"

Giá trị

Giá trị Mô tả
normal Font bình thường (mặc định).
small-caps Hiển thị văn bản bằng chữ in hoa nhỏ.
initial Đặt về giá trị mặc định.
inherit Kế thừa từ phần tử cha.

Ví dụ

Ví dụ chuyển font variant thành small-caps cho hai div.

<!DOCTYPE html> <html> <head> <style> 
  #demo2, #demo1 { 
    font-family: 'times new roman'; 
    font-size: 25px; 
  } 
</style> <script> 
  function changeFontVariant() { 
    document.getElementById("demo1").style.fontVariant = "small-caps"; 
    document.getElementById("demo2").style.fontVariant = "small-caps"; 
    document.getElementById("Sample").innerHTML = "Font variant đã chuyển sang small caps"; 
  } 
</script> </head> <body> 
  <div id="demo1">This is demo text</div> 
  <div id="demo2">This is demo text</div> 
  <p>Nhấn nút để thay đổi font variant của văn bản</p> 
  <button onclick="changeFontVariant()">Thay đổi Font Variant</button> 
  <p id="Sample"></p> 
</body> </html>

Kết quả

Thuộc tính fontVariant trong HTML DOM Style

Sau khi nhấn nút Thay đổi Font Variant:

Thuộc tính fontVariant trong HTML DOM Style