画像を枠内にトリミング

HTML
1
2
3
<figure>
    <a href="#" data-fancybox="gallery"><img src="#" alt=""></a>
</figure>
SCSS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
figure {
    position: relative;
    &::before {
        content:"";
        display: block;
        padding-top: 100%; // 高さを幅の100%に固定(正方形)
    }
    a {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
    }
    img {
        height: 100%;
        width: 100%;
        object-fit: cover;
        @include ie {
            object-fit: none;
            height: auto;
        }
    }
}