구글 AMP – Fit Text

2 min read

Amp 태그 amp-fit-text는 디스플레이를 렌더링하기에 공간이 충분하지 않은 경우 글꼴 크기를 줄입니다. 이 글에서는 이 태그에 대해 자세히 설명합니다.

amp-fit-text가 작동하도록 하려면 다음 스크립트를 추가해야 합니다.

<script async custom-element="amp-fit-text" 
src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>

AmpFit-Text 태그

amp-fit-text 태그의 형식은 다음과 같습니다.
<amp-fit-text width="200"
              height="200"
              layout="responsive">
  Text here
</amp-fit-text>

예제

예제를 통해 이 태그를 더 잘 이해하도록 하겠습니다.

<!doctype html>
<html ⚡ lang="ko">
<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <title>Google AMP - Amp Fit-Text</title>
  <link rel="canonical" href="https://googleblogamp.blogspot.com/2021/01/google-amp-fit.html">
  <meta name="viewport" content="width=device-width,minimum-scale=1">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  <script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
</head>
<body>
<h1>Google AMP - Amp Fit-Text</h1>
<div style="width:150px;height:150px;">
  <amp-fit-text width="150"
                height="150"
                layout="responsive">
    <b>Welcome To TutorialsPoint - You are browsing the best resource for Online Education</b>
  </amp-fit-text>
</div>
</body>
</html>

결과

위에 주어진 코드의 출력은 다음과 같습니다.

구글 AMP – Fit Text

amp-fit-text를 사용하는 디스플레이가 표시되면 콘텐츠가 사용 가능한 공간에 따라 조정을 시도합니다.

Amp-fit-text에는 max-font-sizemin-font-size 2개의 속성이 있습니다.

  • max-font-size를 사용하고 텍스트를 렌더링하는 데 공간을 사용할 수 없는 경우 크기를 줄이고 사용 가능한 공간 내에서 조정하려고 합니다.
  • min-font-size를 지정하고 공백을 사용할 수 없는 경우 텍스트를 자르고 텍스트가 숨겨진 곳에 점을 표시합니다.

예제

max-font-size와 min-font-size를 모두 amp-fit-text에 지정하는 작업 예제를 살펴보겠습니다.

<!doctype html>
<html ⚡ lang="ko">
<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <title>Google AMP - Amp Fit-Text</title>
  <link rel="canonical" href="https://googleblogamp.blogspot.com/2021/01/google-amp-fit.html">
  <meta name="viewport" content="width=device-width,minimum-scale=1">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
  <script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
</head>
<body>
<h1>Google AMP - Amp Fit-Text</h1>
<div style="width:150px;height:150px;">
  <amp-fit-text width="150"
                height="150"
                layout="responsive"
                max-font-size="30"
                min-font-size="25">
    <b>Welcome To TutorialsPoint - You are browsing the best resource for Online Education</b>
  </amp-fit-text>
</div>
</body>
</html>

결과

방문해주셔서 감사합니다. 즐거운 하루 되세요!

관심 있을 만한 글

  • AMP 상용구(boilerplate)와 관련된 오류를 살펴보겠습니다. AMP 상용구와 관련된 오류는 일반적으로 문서의 끝에서 발생하며 일반적으로 다음과 같이 "The manadatory tag ..."라는 텍스트와 함께 표시됩니다: test.html:2:0 The …
  • AMP 유효성 검사 오류 중에서 자바스크립트 관련 오류를 해결해 보겠습니다. Custom JavaScript is not allowed.맞춤 자바스크립트는 허용되지 않습니다. AMP에서는 성능을 보장하기 위해 자바스크립트 사용이 크게 제한됩니다. 스크립트 태그…
  • 다음 유효성 검사 오류 메시지는 특별한 주의가 필요합니다. The tag 'img' should be replaced with an equivalent 'amp-img' tag태그 'img'을(를) 동등한 'amp-img' 태그로 교체해야 합니다. 기존의 HTML…
  • HTML에 대한 기본적인 지식이 있다고 가정하고 간단한 HTML5 페이지를 AMP-HTML로 변환해보겠습니다. 표준 AMP 페이지, 즉 데스크톱 페이지가 없는 독립형 AMP 페이지를 구축하지 않는 한, 일반적으로 전체 HTML 페이지를 AMP-HTML로 변환합니다. …
  • 유효성 검사는 AMP 페이지에 문제가 있을 때 알려주며, 페이지의 어느 부분에서 문제가 발생했는지 알 수 있기 때문에 매우 유용합니다. AMP 페이지의 유효성을 검사하지 않으면 AMP 캐시에 포함되지 않습니다. 즉, 클릭함과 동시에 즉시 로드되는 페이지를 만들지 못합니다…
  • AMP 유효성 검사 오류 중에서 CSS 스타일 시트 관련 오류를 해결해 보겠습니다. The attribute 'href' in tag 'link rel=stylesheet for fonts' is set to the invalid value 'style.css'.'…

댓글 쓰기