CSS: Problems when using object-fit and transform together on webkit

后端 未结 2 414
鱼传尺愫
鱼传尺愫 2021-01-12 18:04

I\'m trying to use both the css property object-fit: cover on an img element to have my image filling its containing div and tra

2条回答
  •  攒了一身酷
    2021-01-12 18:46

    You can create an extra layer, with class wrap, and use this to make the zoom effect

    Your styles are the same, but reasigned

    html, body {
        width: 100%;
        height: 100%
    }
    
    div.category {
        width: 80%;
        height: 150px;
        background-color: yellow;
        margin: 20px;
        overflow: hidden;
        position: relative;
    }
    
    .wrap {
        position: absolute;
        height: 100%;
        width: 100%;
    }
    
    div.category .wrap img {
        display: block;
        height: 100%;
        width: 100%;
        object-fit: cover;
        object-position: center;
    }
    
    /* Transformations */
    
    div.category .wrap {
        transition: transform 0.35s;
        transform:  scale(1.12);
    }
    
    div.category:hover .wrap {
        transform:  scale(1);
    }

提交回复
热议问题