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

Thuộc tính fontSizeAdjust trong HTML DOM Style


Giới thiệu

Thuộc tính fontSizeAdjust trong HTML DOM Style dùng để thiết lập kích thước font dựa trên chiều cao của chữ thường x và chữ hoa X. Nó cung cấp kiểm soát tốt hơn kích thước font so với thuộc tính fontSize thông thường.

Lưu ý: Thuộc tính này chỉ được hỗ trợ trong Mozilla Firefox.

Cú pháp

Thiết lập fontSizeAdjust:

object.style.fontSizeAdjust = "none|number|initial|inherit"

Giá trị

Giá trị Mô tả
none Không điều chỉnh kích thước font (mặc định).
number Dùng để tính tỷ lệ aspect value: chia x-height của font đầu tiên cho font thứ hai và nhân với số cho trước.
initial Đặt về giá trị mặc định.
inherit Kế thừa từ phần tử cha.

Ví dụ

Ví dụ thay đổi fontSizeAdjust từ 0.5 sang 1 cho các div với font khác nhau.

<!DOCTYPE html> <html> <head> <style> 
  .one { 
    font-family: verdana; 
  } 
  .two { 
    font-family: 'times new roman'; 
  } 
  #demo1, #demo2 { 
    font-size-adjust: 0.5; 
  } 
</style> <script> 
  function adjustFontSize() { 
    document.getElementById("demo1").style.fontSizeAdjust = "1"; 
    document.getElementById("demo2").style.fontSizeAdjust = "1"; 
    document.getElementById("Sample").innerHTML = "fontSizeAdjust của văn bản trong div đã tăng lên 1"; 
  } 
</script> </head> <body> 
  <div class="one">This is demo text</div><br/> 
  <div id="demo1" class="one">This is demo text</div><br/> 
  <div class="two">This is demo text</div><br/> 
  <div id="demo2" class="two">This is demo text</div> 
  <p>Nhấn nút để thay đổi fontSizeAdjust</p> 
  <button onclick="adjustFontSize()">Thay đổi fontSizeAdjust</button> 
  <p id="Sample"></p> 
</body> </html>

Kết quả

Thuộc tính fontSizeAdjust trong HTML DOM Style

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

Thuộc tính fontSizeAdjust trong HTML DOM Style