HTML DOM Style fontWeight property
Definition and Usage
fontWeight property sets or returns the font weight.
grammar
Setting fontWeight properties:
Object.style.fontWeight="value"
Back fontWeight properties:
Object.style.fontWeight
值 | 描述 |
---|---|
normal | 默认。字体是 normal(正常的)。 |
lighter | 定义更细的字体。 |
bold | 定义粗体。 |
bolder | 定义更粗的字体。 |
100 200 300 400 500 600 700 800 900 |
定义由细到粗的字符。400 等同于 normal,700 等同于 bold。 |
inherit | fontWeight 属性的值从父元素继承。 |
Browser Support
All major browsers support fontWeight property.
Note: IE7 and earlier versions do not support the "inherit" value.IE8 only provides! DOCTYPE supported "inherit". IE9 support "inherit".
Examples
Examples
Change font-weight:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function displayResult () {
document.getElementById ( "p1") style.fontWeight = "900".;
}
</ Script>
</ Head>
<Body>
<P id = "p1"> This is some text. </ P>
<br>
<Button type = "button" onclick = "displayResult ()"> modify font weight </ button>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function displayResult () {
document.getElementById ( "p1") style.fontWeight = "900".;
}
</ Script>
</ Head>
<Body>
<P id = "p1"> This is some text. </ P>
<br>
<Button type = "button" onclick = "displayResult ()"> modify font weight </ button>
</ Body>
</ Html>
try it"
Style Objects