目录

style fontWeight 属性

示例

将元素的字体粗细设置为"900":

document.getElementById("demo").style.fontWeight = "900";
亲自试一试 »

描述

fontWeight 属性设置或返回文本中字符的显示粗细程度。


浏览器支持

Property
fontWeight Yes Yes Yes Yes Yes

语法

返回 fontWeight 属性:

object.style.fontWeight

设置 fontWeight 属性:

object.style.fontWeight = "normal|lighter|bold|bolder| value|initial|inherit"

属性值

Value Description
normal Font is normal. This is default
lighter Font is lighter
bold Font is bold
bolder Font is bolder
100
200
300
400
500
600
700
800
900
Defines from light to bold characters. 400 is the same as normal, and 700 is the same as bold
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit


技术细节

默认值: 普通的
返回值: 一个字符串,代表字体的粗细
CSS版本 CSS1

更多示例

示例

可能值的演示:

var listValue = selectTag.options[selectTag.selectedIndex].text;
document.getElementById("demo").style.fontWeight = listValue;
亲自试一试 »

示例

返回元素的字体粗细:

alert(document.getElementById("demo").style.fontWeight);
亲自试一试 »

相关页面

CSS教程:CSS 字体

CSS 参考:字体粗细属性

HTML DOM 参考:字体属性