回答編集履歴
1
cssのみで対応する方法を追記
answer
CHANGED
@@ -1,3 +1,45 @@
|
|
1
|
+
興味があったので再挑戦してみました。
|
2
|
+
ただし、以下のコードは画像が横長の場合はうまくいきますが、縦長の場合期待する結果とならないと思われます。
|
3
|
+
※縦長画像の場合、```.icon-top img```の```width```と```height```の値を入れかえると上下が見切れた画像として表示されます。
|
4
|
+
|
5
|
+
``` html
|
6
|
+
<div class="icon-top">
|
7
|
+
<img src="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" alt="">
|
8
|
+
</div>
|
9
|
+
```
|
10
|
+
|
11
|
+
``` css
|
12
|
+
.icon-top img {
|
13
|
+
width: 5rem;
|
14
|
+
height: 5rem;
|
15
|
+
border-radius: 50%;
|
16
|
+
object-fit: cover;
|
17
|
+
}
|
18
|
+
|
19
|
+
@media all and (-ms-high-contrast: none) {
|
20
|
+
.icon-top {
|
21
|
+
width: 5rem;
|
22
|
+
height: 5rem;
|
23
|
+
border-radius: 50%;
|
24
|
+
overflow: hidden;
|
25
|
+
position: relative;
|
26
|
+
}
|
27
|
+
|
28
|
+
.icon-top img {
|
29
|
+
width: auto;
|
30
|
+
height: 100%;
|
31
|
+
min-width: 100%;
|
32
|
+
min-height: 100%;
|
33
|
+
position: absolute;
|
34
|
+
left: 50%;
|
35
|
+
top: 50%;
|
36
|
+
transform: translate(-50%, -50%);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
---
|
42
|
+
|
1
43
|
期待される回答とは異なるかもしれませんが、以下のように```.icon-top```の背景画像扱いとする方法はどうでしょうか?
|
2
44
|
|
3
45
|
``` html
|