01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<title>測試1111111</title>
<style>
*{margin:0;padding:0;}
div{
width: 200px;
height: 200px;
border: 1px solid
#000;
margin-left: 15px;
margin-bottom: 15px;
float: left;
overflow: hidden;
position: relative;
}
div img {
position: absolute;
max-width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
/* 設置四個值爲零,margin:auto;能夠設置元素水平垂直居中 */
}
</style>
</head>
<body>
<div><img src=
"./images/kul.jpg"
alt=
""
></div>
<div><img src=
"./images/lf.png"
alt=
""
></div>
<div><img src=
"./images/timg (1).jpg"
alt=
""
></div>
</body>
</html>
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<title>測試222222</title>
<style>
*{margin:0;padding:0;}
div{
width: 200px;
height: 200px;
line-height: 200px;
border: 1px solid
#000;
margin-left: 15px;
margin-bottom: 15px;
float: left;
text-align: center;
overflow: hidden;
}
div img {
/*採用行內塊的特性進行圖片的垂直居中特性
圖片設置最大寬度和最小寬度;
vertical-align--> 文字對齊方式採用middle 居中
*/
max-width: 200px;
max-height: 200px;
vertical-align: middle;
}
</style>
</head>
<body>
<div><img src=
"./images/kul.jpg"
alt=
""
></div>
<div><img src=
"./images/lf.png"
alt=
""
></div>
<div><img src=
"./images/timg (1).jpg"
alt=
""
></div>
</body>
</html>
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<!DOCTYPE html>
<html lang=
"en"
>
<head>
<meta charset=
"UTF-8"
>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta http-equiv=
"X-UA-Compatible"
content=
"ie=edge"
>
<title>測試3333333</title>
<style>
*{margin:0;padding:0;}
div{
width: 200px;
height: 200px;
border: 1px solid
#000;
margin-left: 15px;
margin-bottom: 15px;
float: left;
overflow: hidden;
position: relative;
}
div img {
/* 寬高100%
設置的是 IMG 標籤的 關於 內容src的寬高屬性會根據內容自動填充,會產生不完整的現象
*/
width: 100%;
height: 100%;
object-fit:none;
/* 默認狀況顯示 */
object-position: center;
/* 圖片內容採用 center 方式進行居中 */
}
</style>
</head>
<body>
<div><img src=
"./images/kul.jpg"
alt=
""
></div>
<div><img src=
"./images/lf.png"
alt=
""
></div>
<div><img src=
"./images/timg (1).jpg"
alt=
""
></div>
</body>
</html>
|