带有<pre> content

时间:2016-06-18 19:55:55

标签: amp-html

<amp-fit-text> is a useful way to fit text in a responsive container. It seems to expect text to wrap however and is preventing vertical overflow. Is it possible to use an <amp-fit-text> tag with <pre> text (or other non-wrap text) to adjust the font-size to avoid the text from overflowing the container horizontally?

1 个答案:

答案 0 :(得分:1)

我不确定这是否是您正在寻找的东西,但我在尝试处理听起来类似的事情时遇到了这个解决方案。我发现vw单位可以根据视口的宽度动态调整字体大小。以下是一些示例代码:

&#13;
&#13;
<!doctype html>
<html amp lang="en">
  <head>
    <meta charset="utf-8">
    <title>asd</title>
    <link rel="canonical" href="http://example.ampproject.org/article-metadata.html" />
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <script type="application/ld+json">
      {
        "@context": "http://schema.org",
        "@type": "NewsArticle",
        "headline": "Open-source framework for publishing content",
        "datePublished": "2015-10-07T12:02:41Z",
        "image": [
          "logo.jpg"
        ]
      }
    </script>
    <style amp-custom>
    .container {
      font-size: 2vw;
    }
    </style>
    <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>
    <h1>TEST</h1>
    <h2>test</h2>
    <p><span>asd</span></p>
    <p><span>ads</span></p>
    
    <p>body</p>
    <p><div class="container"><pre>
echo 'Voluptua consulatu ad mea. Mea tale accumsan neglegentur cu.'
$x = 123;
foo(bar);
    </pre></div></p>
    
  </body>
</html>
&#13;
&#13;
&#13;

我希望这会有所帮助,如果您需要我澄清任何内容,请告诉我。