[JS] Load font

Joey Hong·2020년 11월 27일
0

javascript

목록 보기
2/4
  • 아래는 나눔바른고딕의 fontWeight: 400을 가져온 것이다
let font = new FontFace('NanumBarunGothic', 'url(//cdn.jsdelivr.net/font-nanumlight/1.0/NanumBarunGothicWeb.woff)');
  font.load().then(function(loadedFont)
  {
    document.fonts.add(loadedFont);
  }).catch(function(error) {

  });

document.body.style.fontFamily = 'NanumBarunGothic';

let text = document.createElement('div');
text.innerHTML = `<h4><strong>Hello</strong></h4>`;
  • 하지만 여기서 가져온 NanumBarunGothic은 볼드체가 따로 없어 bold적용이 안된다
  • 따라서 맥과 윈도우의 기본 폰트인 Arial을 사용해보도록 하자
document.body.style.fontFamily = 'Arial';
let text = document.createElement('div');
text.innerHTML = `<h4><strong>Hello</strong></h4>`;

기본 폰트인 Arial에 이렇게 strong을 적용하면 볼드체로 나오는 것을 확인할 수 있다

profile
개발기록

0개의 댓글