HTML DOM fontWeight 속성은 요소의 텍스트 문자의 두께를 설정하거나 반환하는 데 사용됩니다.
다음은 −
의 구문입니다.fontWeight 속성 설정 -
object.style.fontWeight = "normal|lighter|bold|bolder|value|initial|inherit"
위의 속성은 다음과 같이 설명됩니다.
| 값 | 설명 |
|---|---|
| 보통 | 기본값이며 글꼴을 변경하지 않습니다. |
| 가벼움 | 폰티스 라이터 |
| 굵게 | 가벼운 것보다 두꺼운 글꼴로 글꼴을 설정합니다. |
| 굵게 | 글꼴을 볼드체보다 굵은체로 설정합니다. |
| 100 200 300 400 500 600 700 800 900 | 밝은 문자부터 굵은 문자까지 다양한 값을 제공합니다. 일반=400,700=굵게. |
| 초기 | 이 속성을 초기 값으로 초기화합니다. |
| 상속 | 상위 속성 값 상속 |
fontWeight 속성에 대한 예를 살펴보겠습니다 -
예시
<!DOCTYPE html>
<html>
<head>
<style>
#demo2,#demo1 {
font-family: 'times new roman';
font-size: 25px;
}
</style>
<script>
function changeFontWeight() {
document.getElementById("demo1").style.fontWeight="bold";
document.getElementById("demo2").style.fontWeight="bold";
document.getElementById("Sample").innerHTML="The font weight has been changed for the above paragraphs";
}
</script>
</head>
<body>
<div id="demo1" >This is demo text</div>
<div id="demo2">This is demo text</div>
<p>Change the font weight for the text inside above divs by clicking the below button</p>
<button onclick="changeFontWeight()">Change font Weight </button>
<p id="Sample"></p>
</body>
</html> 출력

"글꼴 두께 변경을 클릭하면 " 버튼 -
