#BlackLivesMatter
Do you build things with AMP? Fill out the new AMP Developer Survey!
AMP

amp-fit-text

Description

Expands or shrinks font size to fit the content within the space given.

Required Scripts

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

Usage

Expands or shrinks its font size to fit the content within the space given to it.

The amp-fit-text component allows you to manage the size and fit of text within a specified area. For content contained in an amp-fit-text element, the amp-fit-text component finds the best font size to fit all of the content within the available space. The expected content for amp-fit-text is text or other inline content, but it can also contain non-inline content.

In the following example, the <amp-fit-text> element is nested within a 300x300 blue div block (class fixedblock). For the <amp-fit-text> element, we specified a responsive layout. As a result, the text scales responsively per the aspect ratio provided by the width and height (200x200) of the <amp-fit-text> element, but the text does not exceed the size of its parent.

Lorem ipsum dolor sit amet, has nisl nihil convenire et, vim at aeque inermis reprehendunt.
<div class="fixedblock">
  <amp-fit-text width="200" height="200" layout="responsive">
    Lorem ipsum dolor sit amet, has nisl nihil convenire et, vim at aeque
    inermis reprehendunt.
  </amp-fit-text>
</div>
이 코드 조각을 Playground에서 열기

The following example is similar to the one above, but in this example we specify a max-font-size of 22, so the text is smaller but still fits the space:

Lorem ipsum dolor sit amet, has nisl nihil convenire et, vim at aeque inermis reprehendunt.
<div class="fixedblock">
  <amp-fit-text width="200" height="200" layout="responsive" max-font-size="22">
    Lorem ipsum dolor sit amet, has nisl nihil convenire et, vim at aeque
    inermis reprehendunt.
  </amp-fit-text>
</div>
이 코드 조각을 Playground에서 열기

Overflowing content

If the content of the amp-fit-text overflows the available space, even with a min-font-size specified, the overflowing content is cut off and hidden. WebKit and Blink-based browsers show ellipsis for overflowing content.

In the following example, we specified a min-font-size of 40, which causes the content to exceed the size of its fixed block parent, so the text is truncated to fit the container.

Lorem ipsum dolor sit amet, has nisl nihil convenire et, vim at aeque inermis reprehendunt.
<div class="fixedblock">
  <amp-fit-text width="200" height="200" layout="responsive" min-font-size="40">
    Lorem ipsum dolor sit amet, has nisl nihil convenire et, vim at aeque
    inermis reprehendunt.
  </amp-fit-text>
</div>
이 코드 조각을 Playground에서 열기

Attributes

min-font-size

Specifies the minimum font size as an integer that the amp-fit-text can use.

max-font-size

Specifies the maximum font size as an integer that the amp-fit-text can use.

Common attributes

This element includes common attributes extended to AMP components.

Styling

You can style the amp-fit-text with standard CSS. In particular, you can use text-align, font-weight, color and many other CSS properties, with the main exception of font-size.

Validation

See amp-fit-text rules in the AMP validator specification.

도움이 더 필요하신가요?

이 문서를 수십 번 읽었음에도 여전히 궁금한 점이 남아 있나요? 다른 개발자들도 같은 심정일지 모릅니다. Stack Overflow에서 소통해 보세요.

Stack Overflow로 이동
버그나 누락된 기능을 발견하셨나요?

AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.

GitHub로 이동하기