HTML DOM Style fontStyle 속성은 텍스트의 글꼴 스타일을 설정하거나 반환하는 데 사용됩니다. 요소의 텍스트에 대해 일반, 기울임꼴 또는 사선 스타일을 지정하는 데 사용됩니다.
다음은 −
의 구문입니다.fontStyle 속성 설정 -
object.style.fontStyle = "normal|italic|oblique|initial|inherit"
fontStyle 속성의 예를 살펴보겠습니다 -
예시
<!DOCTYPE html>
<html>
<head>
<style>
#demo2,#demo1 {
font-family: 'times new roman';
font-size: 25px;
}
</style>
<script>
function changeFontStyle() {
document.getElementById("demo1").style.fontStyle="italic";
document.getElementById("demo2").style.fontStyle="italic";
document.getElementById("Sample").innerHTML="The font style has been changed for the above paragraphs.";
}
</script>
</head>
<body>
<div id="demo1" >This is demo text 1</div>
<div id="demo2">This is demo text 2</div>
<p>Change the above divs font style by clicking the below button</p>
<button onclick="changeFontStyle()">Change fontStyle </button>
<p id="Sample"></p>
</body>
</html> 출력

'글꼴 스타일 변경을 클릭하면 " 버튼 -
