본문 바로가기

HTML CSS

html/css) 폰트 font 관련 속성

ch16

폰트 속성
font properties

family, size, weight
style, height..

font(family, size, weight..) 단축속성

 

웹폰트
pc에 폰트가 없으면?
구글폰트

 

예제)

html 구문

  <body>
    <h1>나는 기본 폰트야</h1>
    <!-- 모든 브라우저는 자체 기본 폰트 스택을 보유했다 -->
    <h1 class="gaegu">안녕 나는 gaegu 폰트야</h1>
    <h2 class="roboto">안녕 나는 roboto 폰트야</h2>
    <p class="sunflower">안녕 나는 sunflower 폰트야</p>
  </body>

 

구글웹폰트 링크

<link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      rel="stylesheet"
    />

 

클래스별 폰트 스타일 정의

      .gaegu {
        font-family: "Gaegu", sans-serif;
        font-weight: 400px;
        font-size: 24px;
      }
      .roboto {
        font-family: "Roboto", sans-serif;
        font-weight: 700;
        font-style: italic;
        font-size: 28px;
      }
      .sunflower {
        font-family: "Sunflower", sans-serif;
        font-weight: 500;
        font-size: 20px;
      }

 

결과

 

예제2)

html 구문

<body>
    <h1>채팅 메시지 스타일링</h1>
    <div class="chat-message message-normal">
        안녕? 오늘 기분이 어때? 아주 긴 메시지를 보내볼게요. 이 메시지는 줄 바꿈이 됩니다
    </div>
    <div class="chat-message message-nowrap">
        안녕? 오늘 기분이 어때? 아주 긴 메시지를 보내볼게요. 이 메시지는 줄 바꿈 없이 ..으로 표시됩니다
    </div>
</body>

 

스타일

body{
    padding: 40px;
    font-family: Arial, sans-serif;
}
.chat-message{
    width: 300px;
    border: 1px solid #ccc;
    padding: 10px;
    margin-bottom: 10px;
    background-color: #f0f0f0;
    border-radius: 10px;
    text-decoration: line-through;
}
.message-normal{
    /* 공백 또는 줄바꿈: 기본값 */
    white-space: normal;
}
.message-nowrap{
    /* 공백 또는 줄바꿈: 기본값 */
    white-space: nowrap;
    /* overflow 속성이 들어가야 textoverflow가 적용된다 */
    overflow: hidden;
    text-overflow: ellipsis;
}

 

결과