一段背景图片CSS,自适应手机或电脑端

Longli Lv3

一段背景图片CSS,自适应手机或电脑端

1
2
3
4
5
6
7
8
9
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
82
83
#root,
.App,
body,
html {
min-height: 70vh;
margin: 0;
padding: 0;
margin-top: 1% !important
}

#bg {
-moz-transform: scale(1);
-webkit-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
-webkit-backface-visibility: hidden;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
z-index: -2
}

#bg:after,
#bg:before {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}

#bg:before {
-moz-transition: background-color 2.5s ease-in-out .75s;
-webkit-transition: background-color 2.5s ease-in-out .75s;
-ms-transition: background-color 2.5s ease-in-out;
transition: background-color 2.5s ease-in-out .75s;
-ms-transition-delay: .75s;
background-image: linear-gradient(to top, rgba(255, 255, 255, .4), rgba(255, 255, 255, .4)), url(https://jitsu.oss-cn-beijing.aliyuncs.com/home/img/overlay.png);
background-size: auto, 256px 256px;
background-position: center, center;
background-repeat: no-repeat, repeat;
z-index: 2
}

#bg:after {
-moz-transform: scale(1.125);
-webkit-transform: scale(1.125);
-ms-transform: scale(1.125);
transform: scale(1.125);
-moz-transition: -moz-transform 325ms ease-in-out, -moz-filter 325ms ease-in-out;
-webkit-transition: -webkit-transform 325ms ease-in-out, -webkit-filter 325ms ease-in-out;
-ms-transition: -ms-transform 325ms ease-in-out, -ms-filter 325ms ease-in-out;
transition: transform 325ms ease-in-out, filter 325ms ease-in-out;
background-image: url(example_PC.com);
//example.com替换为PC壁纸url
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 1
}

@media screen and (max-width:960px) {
#bg:after {
-moz-transform: scale(1.125);
-webkit-transform: scale(1.125);
-ms-transform: scale(1.125);
transform: scale(1.125);
-moz-transition: -moz-transform 325ms ease-in-out, -moz-filter 325ms ease-in-out;
-webkit-transition: -webkit-transform 325ms ease-in-out, -webkit-filter 325ms ease-in-out;
-ms-transition: -ms-transform 325ms ease-in-out, -ms-filter 325ms ease-in-out;
transition: transform 325ms ease-in-out, filter 325ms ease-in-out;
background-image: url(example.com);
//example.com替换为PE壁纸url
background-position: center;
background-size: cover;
background-repeat: no-repeat;
z-index: 1
}
}
  • 标题: 一段背景图片CSS,自适应手机或电脑端
  • 作者: Longli
  • 创建于 : 2023-05-22 00:00:00
  • 更新于 : 2025-06-23 00:47:22
  • 链接: https://blog.longli.space/2023/05/22/2023052201/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
一段背景图片CSS,自适应手机或电脑端