Properti HTML DOM Style fontsize
Definisi dan Penggunaan
fontsize set properti atau mengembalikan ukuran font teks.
tatabahasa
Pengaturan properti fontsize:
Object.style.fontSize="value|inherit"
Sifat Kembali fontsize:
Object.style.fontSize
值 | 描述 |
---|---|
xx-small x-small small medium large x-large xx-large |
把字体的尺寸设置为不同的固定尺寸,从 xx-small 到 xx-large。 |
smaller | 把字体尺寸减小一个相对单位。 |
larger | 把字体尺寸增大一个相对单位。 |
length | 使用 px、cm 等单位定义字体尺寸。 |
% | 定义字体尺寸为父元素字体尺寸的某个百分比。 |
inherit | fontSize 属性的值从父元素继承。 |
Dukungan Browser
Semua browser utama mendukung properti fontsize.
Catatan: IE7 dan versi sebelumnya tidak mendukung "mewarisi" nilai.IE8 hanya menyediakan! DOCTYPE didukung "mewarisi". dukungan IE9 "mewarisi".
contoh
contoh
Mengubah ukuran font teks:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi displayResult () {
document.getElementById ( "p1") style.fontSize = "xx-besar" .;
}
</ Script>
</ Kepala>
<Body>
<P id = "p1"> Ini adalah beberapa teks. </ P>
Situs
<Tombol type = "button" onclick = "displayResult ()"> Ubah ukuran huruf </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> Tutorial ini (w3big.com) </ title>
<Script>
Fungsi displayResult () {
document.getElementById ( "p1") style.fontSize = "xx-besar" .;
}
</ Script>
</ Kepala>
<Body>
<P id = "p1"> Ini adalah beberapa teks. </ P>
Situs
<Tombol type = "button" onclick = "displayResult ()"> Ubah ukuran huruf </ button>
</ Body>
</ Html>
Coba »
gaya Objects