IE and Edge fix for object-fit: cover;

前端 未结 6 1603
清歌不尽
清歌不尽 2020-11-27 05:54

I\'m using object-fit: cover; in my CSS for images on a specific page, because they need to stick on the same height. It works great in most browse

6条回答
  •  温柔的废话
    2020-11-27 06:13

    You can use this js code. Just change .post-thumb img with your img.

    $('.post-thumb img').each(function(){           // Note: {.post-thumb img} is css selector of the image tag
        var t = $(this),
            s = 'url(' + t.attr('src') + ')',
            p = t.parent(),
            d = $('
    '); t.hide(); p.append(d); d.css({ 'height' : 260, // Note: You can change it for your needs 'background-size' : 'cover', 'background-repeat' : 'no-repeat', 'background-position' : 'center', 'background-image' : s }); });

提交回复
热议问题