Hexo文章卡片美化

🚦采用自定义css方式实现,无需更改主题文件

创建css文件

[Blogroot/source/css/新建custom.css文件

将以下代码写入刚创建的文件中

悬停卡片效果

1
2
3
4
#recent-posts>.recent-post-item:not(a):hover {
box-shadow: 0 5px 15px rgba(0,0,0,.4);
transform: scale(1.05);
}

卡片擦亮效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#recent-posts > .recent-post-item:not(a)::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 200%;
background: linear-gradient(to right, transparent, white, transparent);
transform: translateX(-200%);
transition: transform 0.5s linear;
z-index: 1;
}
#recent-posts > .recent-post-item:not(a):hover::before {
transform: translateX(100%) skewX(-60deg);
}

卡片最新文章样式

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
@media screen and (min-width: 1280px) {
#recent-posts>.recent-post-item .recent-post-info .newPost {
position:absolute!important;
top: 0!important;
color: #fff!important;
padding: 0 18px;
background-color: var(--anzhiyu-main);
border-radius: 0 0 12px 12px;
right: -8px;
margin-top: 0
}
}

#recent-posts>.recent-post-item:hover .recent-post-info .newPost {
animation: shake .5s infinite
}

@keyframes shake {
0% {
transform: translateX(0)
}

25% {
transform: translateX(-5px)
}

50% {
transform: translateX(5px)
}

75% {
transform: translateX(-5px)
}

100% {
transform: translateX(0)
}
}

引用css文件

在主题配置文件_config.anzhiyu.yml中引用

1
2
3
inject: 
head:
- <link rel="stylesheet" href="/css/custom.css?1">

执行hexo cl && hexo g && hexo s 查看效果