<amp-fit-text> - テキストのサイズをフィットさせる
公開日:
AMPのamp-fit-textは、テキストのフォントサイズを自動で調整するための要素です。この要素で囲ったテキストは、範囲にちょうどよく収まるようにサイズが自動で調整されます。
概要
- 名前
- amp-fit-text
- 可用性
- Stable (安定)
- サポートするレイアウト
- fill,fixed,fixed-height,flex-item,nodisplay,responsive
- 必要なスクリプト
<script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
- 検証
- https://github.com/ampproject/amphtml/blob/master/extensions/amp-fit-text/0.1/validator-amp-fit-text.protoascii
- ドキュメント
- https://www.ampproject.org/docs/reference/extended/amp-fit-text.html
属性
max-font-size
指定例: 32
最大のフォントサイズを数値で指定する。このサイズよりは大きくならない。
min-font-size
指定例: 12
最小のフォントサイズを数値で指定する。このサイズよりは小さくならない。
共通属性
AMPの全てのタグで利用できる共通属性を指定できます。
説明
amp-fit-textを利用するには、専用のライブラリを読み込む必要があります。
HTML
<script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
サンプルコード
HTML
<!doctype html>
<html amp>
<head>
<meta charset="utf-8">
<title>【デモ】<amp-fit-text> - テキストのサイズをフィットさせる</title>
<link rel="canonical" href="https://syncer.jp/Web/AMP/Component/amp-fit-text/">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>
body {
padding: 12px ;
background-color: #fff ;
}
amp-fit-text {
border: 1px solid #000 ;
}
</style>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "NewsArticle",
"headline": "記事のタイトル",
"image": [
"eyecatch.jpg"
],
"datePublished": "2017-08-23T00:00:00+0900"
}
</script>
<script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
<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 src="https://cdn.ampproject.org/v0.js"></script>
</head>
<body>
<h2>6文字の場合</h2>
<amp-fit-text
width="200"
height="200"
layout="fixed"
>SYNCER
</amp-fit-text>
<h2>24文字の場合</h2>
<amp-fit-text
width="200"
height="200"
layout="fixed"
>SYNCERは、個人が運用するウェブサイトです。
</amp-fit-text>
</body>
</html>