Hexo NexT主题移动端样式适配

  自己的博客搭建也有一段时间了,期间整合了挺多个性化功能,都是基于PC端而做的。最近在推自己小站时,朋友间的分享都是基于手机,然而NexT自有的样式在移动端的效果并不大理想,遂萌生了样式适配的想法。Next主题有预留给用户自定义css样式的文件:custom.styl,在这里可以添加自己喜欢的样式代码。

本博客使用版本:NexT v5.1.4

手机端效果:

虽然没那么高大上,不过相比之前看着舒服多了~😁

贴上我的/themes/next/source/css/_custom/custom.styl文件,供参考:

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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#days {
display: block;
color: rgb(7, 179, 155);
font-size: 13px;
margin-top: 15px;
margin-bottom: 15px;
}
.main{
padding-bottom: 150px;
}
/* 自动更换背景图片 */
body {
background:url(https://source.unsplash.com/random/1600x900);
background-repeat: no-repeat;
background-attachment:fixed;
background-position:50% 50%;
}

/* 主页文章添加阴影效果 */
.post {
margin-top: 0px;
margin-bottom: 60px;
padding: 25px;
-webkit-box-shadow: 0 0 5px rgba(202, 203, 203, .5);
-moz-box-shadow: 0 0 5px rgba(202, 203, 204, .5);
}

/* 1~4级标题设置 */
h1,
h2,
h3,
h4,
strong {
font-weight: 600;
color: #2c3e50;
}

/* 一到六级标题设置 */
.posts-expand .post-body h1,
.posts-expand .post-body h2,
.posts-expand .post-body h3,
.posts-expand .post-body h4,
.posts-expand .post-body h5,
.posts-expand .post-body h6 {
padding-top: 10px;
margin-bottom: 10px;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}

/*自定义回到顶部样式*/
.back-to-top {
width: 70px;
height: 900px;
top: -900px;
bottom: unset;
transition: all .5s ease-in-out;
background: url("/images/scroll.png");
/*隐藏箭头图标*/
> i {
display: none;
}
&.back-to-top-on {
bottom: unset;
top: 100vh < (900px + 200px) ? calc( 100vh - 900px - 200px ) : 0px;
}
}

/* 代码块复制按钮 */
.highlight{
/*position: relative;*/
position: static;
}

highlight-wrap {
background: #008b89;
}

.btn-copy {
display: inline-block;
cursor: pointer;
background-color: #eee;
background-image: linear-gradient(#fcfcfc,#eee);
border: 1px solid #d5d5d5;
border-radius: 3px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-appearance: none;
font-size: 13px;
font-weight: 700;
line-height: 20px;
color: #333;
-webkit-transition: opacity .3s ease-in-out;
-o-transition: opacity .3s ease-in-out;
transition: opacity .3s ease-in-out;
padding: 2px 6px;
position: absolute;
right: 5px;
top: 5px;
opacity: 0;
}
.btn-copy span {
margin-left: 5px;
}
.highlight:hover .btn-copy{
opacity: 1;
}

.read-over{
text-align: center;
margin-top: 20px;
color: #ea103d91;
font-size:18px;
}

.share_reward{
margin: 10px auto;
width: 90%;
text-align: center;
}
#rewardButton {
margin: 15px auto;
}

code {
color: #c7254e;
background: #f9f2f4;
border: 1px solid #d6d6d6;
padding:1px 4px;
word-break: break-all;
border-radius:4px;
}
/* 代码块的自定义样式 */
.highlight, pre {
margin: 0px 0;
/*padding: 5px;*/
border-radius: 3px;
}
.highlight, code, pre {
border: 1px solid #d6d6d6;
}

.post-body {
color: #000;
}
.post-body .note{
font-size: 15px;
}

/*文章标题字体*/
.posts-expand .post-title {
font-size: 26px;
font-weight: 700;
text-align: center;
}

/*文章标题动态效果*/
.posts-expand .post-title-link::before {
background-image: linear-gradient(90deg, #a166ab 0%, #ef4e7b 25%, #f37055 50%, #ef4e7b 75%, #a166ab 100%);
}

/* 文章内链接文本样式 */
.post-body a{
color: #0593d3;
border-bottom: none;
border-bottom: 1px solid #0593d3;
&:hover {
color: #fc6423;
}
}

/* 精品文章 began
.jingping{
background : #00a8c3;
padding:2px 4px 2px 4px;
color: #fff;
}
/*热评文章*/
.ds-top-threads li a {
padding-left: 5px;
transition: border-width 0.2s linear 0s, color 0.2s linear 0s;
border-bottom: none;
}
.ds-top-threads li a:hover {
border-left: 8px solid #4d768c;
}

.xiaohutong-img-class{
width:960px;
height:660px;
}

/*友链页样式*/
#links{
margin-top: 5rem;
}
.links-content{
margin-top:1rem;
}
.link-navigation::after {
content: " ";
display: block;
clear: both;
}
.card {
width: 300px;
font-size: 1rem;
padding: 10px 20px;
border-radius: 4px;
transition-duration: 0.15s;
margin-bottom: 1rem;
display:flex;
}
.card:nth-child(odd) {
float: left;
}
.card:nth-child(even) {
float: right;
}
.card:hover {
transform: scale(1.1);
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
}
.card a {
border:none;
}
.card .ava {
width: 3rem!important;
height: 3rem!important;
margin:0!important;
margin-right: 1em!important;
border-radius:4px;
}
.card .card-header {
font-style: italic;
overflow: hidden;
width: 236px;
}
.card .card-header a {
font-style: normal;
color: #2bbc8a;
font-weight: bold;
text-decoration: none;
}
.card .card-header a:hover {
color: #d480aa;
text-decoration: none;
}
.card .card-header .info {
font-style:normal;
color:#a3a3a3;
font-size:14px;
min-width: 0;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
span.focus-links {
font-style: normal;
margin-left: 10px;
position: unset;
left: 0;
padding: 0 7px 0 5px;
font-size: 11px;
border-color: #42c02e;
border-radius: 40px;
line-height: 24px;
height: 22px;
color: #fff !important;
background-color: #42c02e;
display: inline-block;
}
span.focus-links:hover{
background-color: #318024;
}
.friends-btn{
text-align: center;
color: #555!important;
background-color: #fff;
border-radius: 3px;
font-size: 15px;
box-shadow: inset 0 0 10px 0 rgba(0,0,0,.35);
border: none!important;
transition-property: unset;
padding: 0 15px;
margin: inherit;
}
.friends-btn:hover{
color: rgb(255, 255, 255) !important;
border-radius: 3px;
font-size: 15px;
box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, 0.35);
background-image: linear-gradient(90deg, #a166ab 0%, #ef4e7b 25%, #f37055 50%, #ef4e7b 75%, #a166ab 100%);
margin: inherit;
}

/*首页头部样式*/
.header {
/*background: url("/images/header-bk.jpg");*/
}
.site-meta {
float: none;
}
.menu {
float: none;
}
.logo-line-before,
.logo-line-after {
display: none;
}
.menu .menu-item a {
font-size: 14px;
color: rgb(15, 46, 65);
border-radius: 4px;
}
.site-meta {
margin-left: 0px;
text-align: center;
}
.site-meta{
background: #aececb
}
.site-meta .site-title {
font-size: 28px;
font-family: 'Comic Sans MS', sans-serif;
color: #fff;
}
/*首页尾部样式*/
.footer {
background: none;
font-size: 16px;
}
.footer-inner {
font-family: 'Comic Sans MS', sans-serif;
text-align: center;
color: #4c618f;
}
/*侧边栏信息样式修改*/
.site-author-name {
margin: 18px 0 0;
color: #090909;
font-family: 'Comic Sans MS', sans-serif;
}
.links-of-blogroll {
font-size: 13px;
margin-bottom: 32px;
}

.links-of-author {
margin-top: 10px;
}
.site-overview {
text-align: center;
}
.sidebar-inner {
color: #649ab6;
}
.sidebar {
box-shadow: inset 2px 2px 40px #bdb2b2;
}
.sidebar a {
color: #649ab6;
border-bottom-color: #649ab6;
border-bottom: none;
}
.sidebar a:hover {
color: #0c0b0b;
}
.site-state-item {
display: inline-block;
padding: 8px 18px;
border-left: 1px solid #649ab6;
}
.sidebar-nav .sidebar-nav-active {
color: #649ab6;
border-bottom-color: #649ab6;
}
.sidebar-nav li:hover {
color: #0c0b0b;
}
/*侧栏按钮样式*/
.sidebar-toggle {
background: #649ab6;
}
/*文章目录样式*/
.post-toc .nav .active>a {
color: #4f7e96;
}
.post-toc ol a:hover {
color: #7784ba;
}
.sidebar-nav .sidebar-nav-active:hover {
color: #37596c;
}
a {
border-bottom: none;
}
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*首页阅读全文样式*/
.post-button .btn {
color: #555;
background-color: rgb(255, 255, 255);
border-radius: 3px;
font-size: 15px;
box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, 0.35);
border: none !important;
transition-property: unset;
padding: 0px 15px;
margin: inherit;
}
.post-button .btn:hover {
color: rgb(255, 255, 255);
border-radius: 3px;
font-size: 15px;
box-shadow: inset 0px 0px 10px 0px rgba(0, 0, 0, 0.35);
background-image: linear-gradient(90deg, #a166ab 0%, #ef4e7b 25%, #f37055 50%, #ef4e7b 75%, #a166ab 100%);
margin: inherit;
}
.post-button a{
border-bottom: 1px solid #666;
}
.post-button a:hover {
color: #7784ba;
}

/*自定义页脚跳动的心样式*/
@keyframes heartAnimate {
0%,100%{transform:scale(1);}
10%,30%{transform:scale(0.9);}
20%,40%,60%,80%{transform:scale(1.1);}
50%,70%{transform:scale(1.1);}
}
.with-love {
animation: heartAnimate 1.33s ease-in-out infinite;
color: rgb(255, 113, 168);
}

/*修改选择字体块背景颜色*/
::selection {
background: #fff159;
color: #222;
}

.pagination{
margin: 50px;
text-align: center;
border-top:0px;
}
/* 页码数字显示当前页码样式设置 */
.pagination .page-number.current{
background-color: #49b1f5;
background: #49b1f5;
border-radius: 50%;
}
/* 页码样式设置 */
.pagination .page-number{
border: 3px solid #49b1f5;
border-radius: 50%;
}


/* valine 评论系统样式 */
.v .vwrap .vedit .vemojis{
background-color: #fff !important;
}
.v .vwrap .vedit .vpreview {
background-color: #fff !important;
}
.v .vbtn{
background-color: #971212 !important;
color: #fff !important;
}
.v .vwrap .vedit .vctrl{
text-align: left !important;
}
.v .vwrap .vedit .vctrl span{
background-color: #7f7f7f !important;
color: #fff !important;
border-radius: 3px !important;
padding: 3px !important;
}
.v .vlist .vcard .vhead .vsys{
background-color: #fff !important;
}
.v .vlist .vcard .vh .vmeta .vat{
background-color: #177714 !important;
color: #fff !important;
border-radius: 3px !important;
padding-left: 10px !important;
padding-right: 10px !important;
}

/* 适配手机样式 */
@media (max-width: 767px){
/*手机端body体显示*/
body{
background-image: none;
font-size: 16px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #34495e;
}
/*手机端菜单栏样式*/
.menu {
display: flex;
margin-left: 5px;
float: none !important;
}

.menu .menu-item a{
/*font-weight: 600;*/
color: #2c3e50;
font-size: 14px;
padding: 1px 7px;
}
/*选中菜单样式*/
.menu-item-active a:after{
top: -10%;
right: 24px;
}

blockquote{
margin: 10px auto;
border-left: 3px solid #ddd;
}
.back-to-top{
display: none;
right: 0px;
opacity: .2;
}
.posts-expand{
margin: 0 1px;
padding-top: 0px;
}
/*手机屏幕下多级标签样式修改*/
.posts-expand .post-body h1 {
margin: 0 0 0em;
}
.posts-expand .post-body h2,
.posts-expand .post-body h3 {
pointer-events: none;
}
.posts-expand .post-body h1 ,
.posts-expand .post-body h2 ,
.posts-expand .post-body h3 ,
.posts-expand .post-body h4 {
pointer-events: auto;
color: #2c3e50;
}
.posts-expand .post-body h1:before
.posts-expand .post-body h2:before
.posts-expand .post-body h3:before
.posts-expand .post-body h4:before
.posts-expand .post-body h5:before
.posts-expand .post-body h6:before{
display: none;
}
.posts-expand .post-body h2 {
padding-bottom: 0.7em;
border-bottom: 1px solid #ddd;
}
.posts-expand .post-body h3 {
line-height: 1.2;
position: relative;
}
.posts-expand .post-body h3 > a:before {
content: "";
color: #42b983;
position: absolute;
left: -0.7em;
margin-top: -0.05em;
padding-right: 0.5em;
font-size: 1.2em;
line-height: 1;
font-weight: bold;
}

/*段落样式修改*/
.posts-expand .post-body p {
line-height: 1.6em;
text-align: left;
display: contents;
margin: 10px 0;
padding-bottom: 6px;
position: relative;
z-index: 1;
color: #5e6d82;
}
.posts-expand .post-body ul ul,
.posts-expand .post-body ol ul,
.posts-expand .post-body ul ol,
.posts-expand .post-body ol ol {
margin: 0;
}
.posts-expand .post-body a {
color: #000;
font-weight: 300;
}
p{
line-height: 1.6em;
margin: 1.2em 0 -1.2em;
padding-bottom: 1.2em;
position: relative;
z-index: 1;
font-size: 14px;
word-spacing: 0.05em;
}
.posts-expand .post-body ul li{
margin-bottom: 0px !important;
}
li{
font-size: 15px;
color: #5e6d82;
}
.post-button a {
font-size: 16px;
}
.posts-expand .post-meta {
font-size: 10px;
text-align: center;
margin: 1px 0 20px 0;
}
/*设置不展示字数统计*/
.posts-expand .post-meta .post-wordcount{
display: none;
}
/*手机端显示评论数*/
.posts-expand .post-comments-count {
+mobile() { display: unset; }
}

.page-post-detail .post-meta{
margin-bottom: 0px;
}
.posts-expand .post-title {
margin: 10px;
}

.page-post-detail .post-title {
font-weight: 600;
font-size: 20px !important;
padding-top: 10px;
padding-bottom: 15px;
}

.my_post_copyright{
width: 95%;
padding: .1em 1em;
font-size: .73rem
margin: .8em auto 0
}
.my_post_copyright p{
font-size: 13px;
margin: 5px;
line-height: 1.2em;
padding-bottom: 0.5em;
}
}
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
/*适应手机屏幕设置*/
@media (max-width: 767px) {
.header-inner {
margin-bottom: 10px !important;
background: none;
overflow: auto; /*下拉标题是否浮动*/
}
.posts-expand .post-body h1 {
padding-top: 20px;
}
.post-button {
text-align: center;
}
.posts-expand .post-body h2,
.posts-expand .post-body h3 {
pointer-events: none;
}
.posts-expand .post-body h1 ,
.posts-expand .post-body h2 ,
.posts-expand .post-body h3 ,
.posts-expand .post-body h4 {
pointer-events: auto;
color: #2c3e50;
}
.posts-expand .post-body h1:before
.posts-expand .post-body h2:before
.posts-expand .post-body h3:before
.posts-expand .post-body h4:before
.posts-expand .post-body h5:before
.posts-expand .post-body h6:before{
display: none;
}
.posts-expand .post-body h2 {
padding-bottom: 0.7em;
border-bottom: 1px solid #ddd;
}
.posts-expand .post-body h3 {
line-height: 1.2;
position: relative;
}
}
/*手机端显示设置信息*/
@media (max-width: 767px)
{
/*手机端代码行上text文档设置*/
.highlight figcaption{
font-size: 12px;
}
/*手机端显示代码行数背景设置*/
.highlight .gutter pre{
padding-left: 2px;
}

/*手机端显示代码行数字体大小*/
.highlight, pre{
font-size: 10px;
}
/*手机端显示代码字体大小*/
.code span{
font-size: 12px;
}
div#comments.comments.v{
margin-left: 0px !important;
margin-right: 0px !important;
}
}

/*手机适配文章底部信息*/
@media (max-width: 767px) {
.main{
padding-bottom: 130px;
}
.footer{
font-size: 14px;
}
.read-over{/*本文阅读结束*/
text-align: center;
margin-top: 20px;
color: #ea103d91;
font-size: 12px;
}
.share_reward{/*打赏*/
font-size: 12px;
padding: 10px 0;
margin: 5px auto;
width: 90%;
text-align: center;
}
#rewardButton {
margin: 15px auto;
}
#rewardButton span {
display: inline-block;
width: 50px;
height: 35px;
}
#QR{
padding-top: 5px;
}
#QR a{
border:0;
}
#QR img{
width: 60px;
display: inline-block;
margin: 0.8em 2em 0 2em;
}
.post-copyright{
padding: .1em .5em;
margin: 0em 0 0;
border-left: 2px solid #ff1700;
}
.post-copyright li{
font-size: 13.5px;
}
.posts-expand .post-tags{
margin-top: 20px;
font-size: 8px;
}
.post-nav-item a{
font-size: 12px;
line-height: unset;
}
.pagination{
margin: 20px;
text-align: center;
border-top:0px;
}
/*TopX适应手机屏幕设置*/
#top p{
font-size: 13.5px;
display: inline-block;
}
.post-body .note{
margin: 10px auto;
font-size: 14px;
}
.post-body .note.info p{
font-size: 13px;
}
.post-body .tabs .tab-content .note {
margin: 10px auto;
font-size: 14px;
}

}
@media (max-width: 767px) {

/*小胡同背景图*/
.xiaohutong-img-class{
width:360px;
height:260px;
}

/* 小胡同里tab页*/
.post-body .tabs ul.nav-tabs{
display: flex;
}

/*手机友链页*/
.card{
width: 88%;
padding: 3px 20px;
margin-bottom: 0rem;
}
#links {
margin-top: 3rem;
}

}

注意:样式不能保证完全兼容,需要你根据自身情况进行调整。

很多样式我也是学着改的,毕竟不是很擅长。。参考了Sanarous大神的文章,做的真的很不错,值得借鉴和学习!

hexo博客界面美化2.0

点击查看

本文标题:Hexo NexT主题移动端样式适配

文章作者:北宸

发布时间:2019年08月31日 - 11:23:29

最后更新:2019年09月13日 - 23:26:41

原始链接:http://leafjame.github.io/posts/507826828.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------
0%