优化代码适配手机端及复制按钮

我帮您精简和优化了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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Welcome!My Friend</title>
<style>
:root {
--primary: #4a89dc;
--secondary: #f5f7fa;
--text: #333;
--light: #fff;
--border: #e6e9ed;
--success: #8cc152;
--error: #da4453;
}

* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background-color: #f9f9f9;
color: var(--text);
line-height: 1.5;
padding: 15px;
-webkit-text-size-adjust: 100%;
}

.container {
max-width: 100%;
background: var(--light);
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
overflow: hidden;
margin: 0 auto;
}

.header {
background: var(--primary);
color: white;
padding: 1.2rem 1rem;
text-align: center;
position: relative;
}

.avatar {
width: 70px;
height: 70px;
border-radius: 50%;
border: 3px solid white;
object-fit: cover;
margin: 0 auto 0.8rem;
display: block;
background: #e9ecef;
}

.content {
padding: 1.2rem;
}

.section {
margin-bottom: 1.5rem;
}

h1 {
font-size: 1.3rem;
margin-bottom: 0.5rem;
color: var(--light);
}

h2 {
font-size: 1.15rem;
color: var(--primary);
margin-bottom: 0.8rem;
padding-bottom: 0.3rem;
border-bottom: 2px solid var(--primary);
}

p, li {
font-size: 0.95rem;
margin-bottom: 0.8rem;
}

ul {
padding-left: 1.2rem;
margin-bottom: 1rem;
}

.form-group {
margin-bottom: 1.2rem;
}

label {
display: block;
margin-bottom: 0.4rem;
font-weight: 500;
}

input {
width: 100%;
padding: 0.8rem;
border: 1px solid var(--border);
border-radius: 8px;
font-size: 1rem;
margin-bottom: 0.5rem;
}

input:focus {
border-color: var(--primary);
outline: none;
box-shadow: 0 0 0 2px rgba(74, 137, 220, 0.1);
}

button {
background: var(--primary);
color: white;
border: none;
padding: 0.8rem;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
font-weight: 500;
width: 100%;
transition: opacity 0.2s;
-webkit-tap-highlight-color: transparent;
}

button:active {
opacity: 0.9;
}

.language-toggle {
position: absolute;
top: 1rem;
right: 1rem;
background: rgba(255,255,255,0.2);
border: none;
color: white;
padding: 0.3rem 0.8rem;
border-radius: 20px;
cursor: pointer;
font-size: 0.8rem;
}

.hidden {
display: none;
}

.message {
padding: 0.8rem;
border-radius: 8px;
margin-bottom: 1rem;
font-size: 0.9rem;
}

.error {
color: var(--error);
background: #fce4e6;
}

.success {
color: var(--success);
background: #f0f8e9;
}

/* 复制按钮优化 */
.server-address-container {
display: flex;
margin: 0.8rem 0;
}

.server-address {
background: var(--secondary);
padding: 0.8rem;
border-radius: 8px 0 0 8px;
font-family: monospace;
word-break: break-all;
font-size: 0.9rem;
flex: 1;
border: 1px solid var(--border);
border-right: none;
}

.copy-btn {
width: 44px;
background: var(--primary);
border: none;
border-radius: 0 8px 8px 0;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
padding: 0;
}

.copy-icon {
width: 18px;
height: 18px;
}

/* 平板适配 */
@media (min-width: 768px) {
.container {
max-width: 500px;
}

body {
padding: 20px;
}
}
</style>
</head>
<body>
<!-- 保持原有HTML结构不变 -->
<!-- ... -->
</body>
</html>

主要优化点:

  1. 移除了冗余CSS

    • 删除了重复的视口meta标签
    • 移除了不必要的:hover效果(移动端不适用)
    • 简化了字体栈和基础样式
  2. 移动端优先改进

    • 减少了整体padding和margin
    • 缩小了头像尺寸(70px)
    • 调整了字体大小层级
    • 添加了-webkit-text-size-adjust: 100%防止iOS文字放大
  3. 复制按钮优化

    • 固定宽度44px(最小可点击区域)
    • 移除了文字显示,仅保留图标
    • 简化了交互效果
  4. 交互优化

    • :active替代:hover更适合移动端
    • 添加了-webkit-tap-highlight-color改善点击反馈
    • 简化了过渡动画
  5. 性能优化

    • 减少了阴影和过渡效果的数量
    • 简化了选择器
    • 移除了不必要的!important

这个版本更加简洁,专注于移动端体验,同时保留了所有核心功能。复制按钮现在更加紧凑,整体布局在手机上显示更加协调。

时间: 2025-04-11T22:48:40


👤 用户

看看下面的代码有没有可以提升的地方,尤其要适配好手机端,我注意到复制按钮的背景在浏览器中显示出来的效果很长,能不能帮我修正下

Welcome!My Friend