Amphtml: How to override `object-fit: contain` for amp-img inside amp-carousel slides?

Created on 9 Jan 2019  路  4Comments  路  Source: ampproject/amphtml

I want to create amp-carousel with the slides type. Images should have object-fit: cover.

<amp-carousel lightbox
              type="slides"
              layout="responsive"
              width="640"
              height="480">
                <amp-img class="cover"
                         layout="fill"
                         src="...">
                </amp-img>
</amp-carousel>

But images have default object-fit: contain property.
amp-img.cover > img { object-fit: cover } doesn't work, because .amp-carousel-slide>.i-amphtml-replaced-content { object-fit: contain } has more specificity.
I can't use !important and .i-amp-* rules, because they are forbidden.
Please, help

Bug

Most helpful comment

You could do something like:

amp-img.cover.cover > img {
  object-fit: cover;
}

I think two .covers should handle it. If not, you could add a third one. This is something we can look into making easier with the new version of amp-carousel.

All 4 comments

/to @sparhami /cc @nainar

You could do something like:

amp-img.cover.cover > img {
  object-fit: cover;
}

I think two .covers should handle it. If not, you could add a third one. This is something we can look into making easier with the new version of amp-carousel.

Thanks. It works

As a general rule you can fake !important by bumping the specificity with id's:

So

.foo { color: red!important; }

becomes

:not(#X):not(#X).foo { color: red; }

Generally adding two id's is enlough but you can add more :not(#X)'s if you need to.

Was this page helpful?
0 / 5 - 0 ratings