hexo-keep首页样式自定义
kai (¬‿¬)

建站和美化汇总

注:本文仅限于keep主题

0.说明

红框圈起来的部分是本文要改编的地方。

配置文件中可以直接配置的不谈。

首页原始效果:

image-20220108121632136

修改后:

image-20220108135000317

首页下文章列表原始效果:

由于5和6都是白色背景,看起来只有文章列表

image-20220108150058976

修改后:

image-20220108150426715

1.一号框半透明

目标:设置半透明,因为后面想改背景,半透明好看一点。

打开文件Hexo\themes\keep\source\css\layout\_partial\header.styl

在其中找到下面代码:

1
2
3
4
5
6
7
8
9
10
.header-wrapper {
width: 100%;
height: 100%;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: center;
background: var(--background-color);
padding-top: $scroll-progress-bar-height;
......

修改background的值即可。

比如background: rgba(255,255,255,0.9),白色,不透明度0.9。

2.二号框背景

配置文件中可以直接改的缺点:

  • 改了之后原来的飘浮色块会消失
  • 新背景的范围不包括一号框位置

直接修改源文件css样式:

打开文件Hexo\themes\keep\source\css\layout\page.styl

找到以下代码:

1
2
3
4
5
6
7
8
.page-container {
position: relative;
box-sizing: border-box;
width: 100%;
height: auto;

background: var(--background-color);
......

修改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.page-container {
position: relative;
box-sizing: border-box;
width: 100%;
height: auto;

/*背景图片路径*/
background: url("https://cdn.jsdelivr.net/gh/kaix2301/pictures/img202201081000420.jpg");
/*背景图片不重复多次显示*/
background-repeat: no-repeat;
/*窗口放缩时背景图片中心始终在屏幕中心*/
background-position: center;
/*背景图片固定,不滚动*/
background-attachment: fixed;
/*图片大小自适应窗口大小*/
background-size: cover ;
......

修改和增加的代码上面做了说明,可自行修改和取舍。

3.三号框样式

背景更换很可能导致原来的文字看不清楚,可修改文字样式。

打开文件Hexo\themes\keep\source\css\layout\_partial\first-screen.styl

找到以下代码:

1
2
3
4
5
6
7
8
9
10
11
.description {
font-weight: bold;
font-size: $first-screen-font-size;
line-height: 1.8;
text-align: center;
color: var(--default-text-color);

+keep-tablet() {
font-size: $first-screen-font-size * 0.9;
}
}

修改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.description {
background: rgba(50,50,50,0.4); /*字体背景颜色和透明的*/
padding: 5px 20px; /*字体背景框的大小*/
border-radius: 5px; /*圆角*/
font-weight: bold;
font-size: $first-screen-font-size;
line-height: 1.8;
text-align: center;
color: rgb(230,230,230); /*字体颜色*/

+keep-tablet() {
font-size: $first-screen-font-size * 0.9;
}
}

修改和增加的代码上面做了说明,可自行修改和取舍。

4.四号框样式

目前还没改,不过改的话可以在下面位置改。

打开文件Hexo\themes\keep\source\css\layout\_partial\first-screen.styl

找到以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.s-icon-list {
position: absolute;
bottom: 0;
font-size: $first-screen-icon-size;
text-align: center;

+keep-tablet() {
font-size: $first-screen-icon-size * 0.9;
}

.s-icon-item {
margin-right: 20px;
cursor: pointer;
line-height: 2;

&:last-child {
margin-right: 0;
}
}
}

5.五号框背景

在有文字内容的页面设一个简洁背景,好看但不影响阅读。

打开文件Hexo\themes\keep\source\css\layout\page.styl

找到以下代码:

1
2
3
4
5
6
.page-main-content {
padding-top: $header-height;
position: relative;

.header-shrink & {
......

增加四条代码,修改为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
.page-main-content {
padding-top: $header-height;
position: relative;

/*背景图片路径*/
background: url("https://cdn.jsdelivr.net/gh/kaix2301/pictures/img202201072225073.png");
/*背景图片不重复多次显示*/
background-repeat: no-repeat;
/*窗口放缩时背景图片中心始终在屏幕中心*/
background-position: center;
/*背景图片固定,不滚动*/
background-attachment: fixed;
/*图片大小自适应窗口大小*/
background-size: cover ;

.header-shrink & {
......

修改和增加的代码上面做了说明,可自行修改和取舍。

设置完此背景,除首页第一个背景外,其他页面都为此背景。

6.六号框全透明

此位置默认为白色背景,改为全透明。

打开文件Hexo\themes\keep\source\css\layout\home-content.styl

在开始位置找到以下代码:

1
2
3
.home-content-container {
background: var(--background-color);
......

修改为:

1
2
3
.home-content-container {
background: rgba(255,255,255,0);
......

7.七号框半透明

此位置默认为白色背景,改为半透明。

打开文件Hexo\themes\keep\source\css\layout\home-content.styl

在开始位置找到以下代码:

1
2
3
4
5
6
7
8
.home-article-item {
position: relative;
keep-container(true, 1.015, 1.015, 28px, 38px);

.top-icon {
position: absolute;
top: 10px;
......

加一条,修改为:

1
2
3
4
5
6
7
8
9
10
.home-article-item {
position: relative;
keep-container(true, 1.015, 1.015, 28px, 38px);

background: rgba(255,255,255,0.8);/*白色半透明*/

.top-icon {
position: absolute;
top: 10px;
......
  • 本文标题:hexo-keep首页样式自定义
  • 本文作者:kai
  • 创建时间:2022-01-08 12:09:48
  • 本文链接:https://kainote.top/2022/01/08/hexo-keep首页样式自定义/
  • 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
 评论