回答編集履歴

1

cssのみで対応する方法を追記

2017/06/27 05:48

投稿

退会済みユーザー
test CHANGED
@@ -1,3 +1,87 @@
1
+ 興味があったので再挑戦してみました。
2
+
3
+ ただし、以下のコードは画像が横長の場合はうまくいきますが、縦長の場合期待する結果とならないと思われます。
4
+
5
+ ※縦長画像の場合、```.icon-top img```の```width```と```height```の値を入れかえると上下が見切れた画像として表示されます。
6
+
7
+
8
+
9
+ ``` html
10
+
11
+ <div class="icon-top">
12
+
13
+ <img src="https://mdn.mozillademos.org/files/6457/mdn_logo_only_color.png" alt="">
14
+
15
+ </div>
16
+
17
+ ```
18
+
19
+
20
+
21
+ ``` css
22
+
23
+ .icon-top img {
24
+
25
+ width: 5rem;
26
+
27
+ height: 5rem;
28
+
29
+ border-radius: 50%;
30
+
31
+ object-fit: cover;
32
+
33
+ }
34
+
35
+
36
+
37
+ @media all and (-ms-high-contrast: none) {
38
+
39
+ .icon-top {
40
+
41
+ width: 5rem;
42
+
43
+ height: 5rem;
44
+
45
+ border-radius: 50%;
46
+
47
+ overflow: hidden;
48
+
49
+ position: relative;
50
+
51
+ }
52
+
53
+
54
+
55
+ .icon-top img {
56
+
57
+ width: auto;
58
+
59
+ height: 100%;
60
+
61
+ min-width: 100%;
62
+
63
+ min-height: 100%;
64
+
65
+ position: absolute;
66
+
67
+ left: 50%;
68
+
69
+ top: 50%;
70
+
71
+ transform: translate(-50%, -50%);
72
+
73
+ }
74
+
75
+ }
76
+
77
+ ```
78
+
79
+
80
+
81
+ ---
82
+
83
+
84
+
1
85
  期待される回答とは異なるかもしれませんが、以下のように```.icon-top```の背景画像扱いとする方法はどうでしょうか?
2
86
 
3
87