Search code examples
htmlcssamp-htmlblogspot

Caption in AMP-Carousel Not Working


I add caption <div class="caption"> in my amp-carousel beside amp-img. When the device turns into mobile, caption looks half hidden.

enter image description here

Here's my code:

<amp-carousel autoplay='' delay='6000' height='340' layout='responsive' type='slides' width='824'>
    <div>
        <div>
            <amp-img alt='' height='240' layout='responsive' src='image-link-here' width='824'/>
            <div class='caption'>
                <p class='text-inside'><em>Pertama</em>, kode yang ditulis dalam membangun website anda harus tervalidasi menggunakan versi HTML, PHP atau CSS kompatibel atau terupdate sehingga mesin pencari dapat melakukan <em>crawling website</em> anda.</p>
            </div>
        </div>

    </div>
    <div>
        <div>
            <amp-img alt='' height='240' layout='responsive' src='image-link-here' width='824'/>
            <div class='caption'>
                <p class='text-inside'><em>Kedua</em>, loading speed website harus cepat, aman dan <em>mobile friendly</em> (responsive sesuai device yang digunakan semua user).</p>
            </div>
        </div>
    </div>
    <div>
        <div>
            <amp-img alt='' height='240' layout='responsive' src='image-link-here' width='824'/>
            <div class='caption'>
                <p class='text-inside'><em>Ketiga</em>, konten website anda harus unik, berguna/bermanfaat bagi visitor dan teroptimasi (on page SEO) atau SEOptin sebut sebagai <b>website UMT</b> (<em>Unik, Manfaat, Teroptimasi</em>).</p>
            </div>
        </div>
    </div>
    <div>
        <div>
            <amp-img alt='' height='240' layout='responsive' src='image-link-here' width='824'/>
            <div class='caption'>
                <p class='text-inside'><em>Keempat</em>, tulisan di konten website anda sudah diakui (UMT) oleh website yang relevan (sama niche) atau website terbaik lainnya seperti wikipedia, website edu dsb.</p>
            </div>
        </div>
    </div>
</amp-carousel>

In CSS:

amp-carousel{
margin-bottom:25px;
}
p.text-inside{
background:#fff;
padding:15px;
border-radius:0px 0px 3px 3px;
border-left:1px solid #DEDEDE;
border-right:1px solid #DEDEDE;
border-bottom:1px solid #DEDEDE;
font-family:&quot;Tahoma&quot;,sans-serif;
font-size:14px;
letter-spacing:1px;
color:#777;
}
p.text-inside em,p.text-inside strong,p.text-inside b{
font-family:&quot;Tahoma&quot;,sans-serif;
font-size:14px;
letter-spacing:1px;
color:#444;
}

Live preview


Solution

  • In this case use amp-fit-text

    amp-fit-text : Expands or shrinks its font size to fit the content within the space given to it.

    Code

    <!doctype html>
    <html ⚡>
     <head>
       <meta charset="utf-8">
       <link rel="canonical" href="carousel.html">
       <meta name="viewport" content="width=device-width,minimum-scale=1,initial-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 src="https://cdn.ampproject.org/v0.js"></script>
       <script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
       <script async custom-element="amp-fit-text" src="https://cdn.ampproject.org/v0/amp-fit-text-0.1.js"></script>
       <style amp-custom>
        amp-carousel{
    margin-bottom:25px;
    }
    p.text-inside{
    background:#fff;
    padding:15px;
    border-radius:0px 0px 3px 3px;
    border-left:1px solid #DEDEDE;
    border-right:1px solid #DEDEDE;
    border-bottom:1px solid #DEDEDE;
    font-family:&quot;Tahoma&quot;,sans-serif;
    font-size:14px;
    letter-spacing:1px;
    color:#777;
    }
    p.text-inside em,p.text-inside strong,p.text-inside b{
    font-family:&quot;Tahoma&quot;,sans-serif;
    font-size:14px;
    letter-spacing:1px;
    color:#444;
    }
      </style>
     </head>
     <body>
     <amp-carousel controls autoplay='' delay='6000' height='440' layout='responsive' type='slides' width='824'>
        <div>
            <div>
                <amp-img alt='' height='240' layout='responsive' src='https://dummyimage.com/840x240/000/f00' width='824'/>
                <amp-fit-text layout="responsive"
          width="824"
          height="200">
                <div class='caption'>
                    <p class='text-inside'><em>Pertama</em>, kode yang ditulis dalam membangun website anda harus tervalidasi menggunakan versi HTML, PHP atau CSS kompatibel atau terupdate sehingga mesin pencari dapat melakukan <em>crawling website</em> anda.</p>
                </div>
                </amp-fit-text>
            </div>
    
        </div>
        <div>
            <div>
                <amp-img alt='' height='240' layout='responsive' src='https://dummyimage.com/840x240/000/0f0' width='824'/>
                <amp-fit-text layout="responsive"
          width="824"
          height="200">
                <div class='caption'>
                    <p class='text-inside'><em>Kedua</em>, loading speed website harus cepat, aman dan <em>mobile friendly</em> (responsive sesuai device yang digunakan semua user).</p>
                </div>
                </amp-fit-text>
            </div>
        </div>
        <div>
            <div>
                <amp-img alt='' height='240' layout='responsive' src='https://dummyimage.com/840x240/000/00f' width='824'/>
                <amp-fit-text layout="responsive"
          width="824"
          height="200">
                <div class='caption'>
                    <p class='text-inside'><em>Ketiga</em>, konten website anda harus unik, berguna/bermanfaat bagi visitor dan teroptimasi (on page SEO) atau SEOptin sebut sebagai <b>website UMT</b> (<em>Unik, Manfaat, Teroptimasi</em>).</p>
                </div>
                </amp-fit-text>
            </div>
        </div>
        <div>
            <div>
                <amp-img alt='' height='240' layout='responsive' src='https://dummyimage.com/840x240/000/fff' width='824'/>
                <amp-fit-text layout="responsive"
          width="824"
          height="200">
                <div class='caption'>
                    <p class='text-inside'><em>Keempat</em>, tulisan di konten website anda sudah diakui (UMT) oleh website yang relevan (sama niche) atau website terbaik lainnya seperti wikipedia, website edu dsb.</p>
                </div>
                </amp-fit-text>
            </div>
        </div>
    </amp-carousel>
     </body>
    </html>
    

    Example Here

    For more reference visit:

    1. amp-fit-text

    2. Image Galleries with amp-carousel