Skip to content

Commit f314f6a

Browse files
committed
更改页面布局defau.html 增加样式custom.css
1 parent abc5f5f commit f314f6a

3 files changed

Lines changed: 204 additions & 21 deletions

File tree

‎_layouts/default.html‎

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,69 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77

88
{% seo %}
9+
<!-- 1. 加载主题默认样式(保持不变,先加载主题,再加载自定义样式,保证自定义样式优先级) -->
910
<link rel="stylesheet" href="{{ "/assets/css/style.css?v=" | append: site.github.build_revision | relative_url }}">
11+
<!-- 2. 引用外部自定义布局样式(关键:分离样式,避免内嵌冲突) -->
12+
<link rel="stylesheet" href="{{ "/assets/css/custom-layout.css" | relative_url }}">
13+
1014
<!--[if lt IE 9]>
1115
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script>
1216
<![endif]-->
1317
{% include head-custom.html %}
1418
</head>
1519
<body>
16-
<div class="wrapper">
17-
<header>
18-
<h1><a href="{{ "/" | absolute_url }}">{{ site.title | default: site.github.repository_name }}</a></h1>
20+
<!-- 整体容器:添加精准类名 ty-blog-container -->
21+
<div class="ty-blog-container">
22+
<!-- 左侧侧边栏:添加精准类名 ty-blog-sidebar,移除主题默认 header 类(避免冲突) -->
23+
<div class="ty-blog-sidebar">
24+
<h1 class="ty-blog-sidebar__title">
25+
<a href="{{ "/" | absolute_url }}" class="ty-blog-sidebar__link">{{ site.title | default: site.github.repository_name }}</a>
26+
</h1>
1927

2028
{% if site.logo %}
21-
<img src="{{site.logo | relative_url}}" alt="Logo" />
29+
<!-- Logo:添加精准类名 ty-blog-sidebar__logo -->
30+
<img src="{{site.logo | relative_url}}" alt="Logo" class="ty-blog-sidebar__logo" />
2231
{% endif %}
2332

24-
<p>{{ site.description | default: site.github.project_tagline }}</p>
33+
<!-- 描述文字:添加精准类名 ty-blog-sidebar__desc -->
34+
<p class="ty-blog-sidebar__desc">{{ site.description | default: site.github.project_tagline }}</p>
2535

2636
{% if site.github.is_project_page %}
27-
<p class="view"><a href="{{ site.github.repository_url }}">View the Project on GitHub <small>{{ site.github.repository_nwo }}</small></a></p>
37+
<p class="ty-blog-sidebar__link view">
38+
<a href="{{ site.github.repository_url }}" class="ty-blog-sidebar__link">View the Project on GitHub <small>{{ site.github.repository_nwo }}</small></a>
39+
</p>
2840
{% endif %}
2941

3042
{% if site.github.is_user_page %}
31-
<p class="view"><a href="{{ site.github.owner_url }}">View My GitHub Profile</a></p>
43+
<p class="ty-blog-sidebar__link view">
44+
<a href="{{ site.github.owner_url }}" class="ty-blog-sidebar__link">View My GitHub Profile</a>
45+
</p>
3246
{% endif %}
3347

3448
{% if site.show_downloads %}
35-
<ul class="downloads">
36-
<li><a href="{{ site.github.zip_url }}">Download <strong>ZIP File</strong></a></li>
37-
<li><a href="{{ site.github.tar_url }}">Download <strong>TAR Ball</strong></a></li>
38-
<li><a href="{{ site.github.repository_url }}">View On <strong>GitHub</strong></a></li>
49+
<!-- 下载列表:添加精准类名 ty-blog-sidebar__downloads -->
50+
<ul class="ty-blog-sidebar__downloads">
51+
<li><a href="{{ site.github.zip_url }}" class="ty-blog-sidebar__link">Download <strong>ZIP File</strong></a></li>
52+
<li><a href="{{ site.github.tar_url }}" class="ty-blog-sidebar__link">Download <strong>TAR Ball</strong></a></li>
53+
<li><a href="{{ site.github.repository_url }}" class="ty-blog-sidebar__link">View On <strong>GitHub</strong></a></li>
3954
</ul>
4055
{% endif %}
41-
</header>
42-
<section>
56+
</div>
4357

44-
{{ content }}
58+
<!-- 右侧文章内容区:添加精准类名 ty-blog-content -->
59+
<div class="ty-blog-content">
60+
<!-- 文章内容(不变) -->
61+
{{ content }}
4562

46-
</section>
47-
<footer>
48-
{% if site.github.is_project_page %}
49-
<p>This project is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a></p>
50-
{% endif %}
51-
</footer>
63+
<!-- 页脚:移到内容区内,添加精准类名 ty-blog-footer(优化位置,跟随文章底部) -->
64+
<footer class="ty-blog-footer">
65+
{% if site.github.is_project_page %}
66+
<p>This project is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a></p>
67+
{% endif %}
68+
<p>&copy; {{ site.time | date: "%Y" }} {{ site.title | default: site.github.repository_name }}</p> <!-- 新增版权信息,更完整(可选) -->
69+
</footer>
70+
</div>
5271
</div>
5372
<script src="{{ "/assets/js/scale.fix.js" | relative_url }}"></script>
5473
</body>
55-
</html>
74+
</html>

‎assets/css/custom-layout.css‎

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/* ==============================================
2+
自定义博客布局:侧边栏居左 + 文章内容居中
3+
类名前缀:ty-blog-* 避免与主题样式冲突
4+
兼容深色模式(使用 CSS 变量 + 主题默认色值)
5+
============================================== */
6+
7+
/* 1. 整体容器 - 弹性布局核心(避免覆盖主题 .wrapper) */
8+
.ty-blog-container {
9+
max-width: 1280px; /* 网页最大宽度,保证大屏美观 */
10+
margin: 0 auto; /* 整体在页面水平居中 */
11+
display: flex; /* 启用弹性布局,实现左右排列 */
12+
padding: 30px 20px;/* 上下/左右内边距,避免内容贴边 */
13+
gap: 50px; /* 侧边栏和内容区的间距(比 margin 更优雅) */
14+
align-items: flex-start; /* 侧边栏和内容区顶部对齐,避免错位 */
15+
box-sizing: border-box; /* 内边距不影响宽度计算,避免溢出 */
16+
}
17+
18+
/* 2. 左侧侧边栏 - 精准类名(ty-blog-sidebar) */
19+
.ty-blog-sidebar {
20+
width: 280px; /* 侧边栏固定宽度,可自定义调整 */
21+
flex-shrink: 0; /* 防止侧边栏被内容区压缩,保证宽度稳定 */
22+
text-align: center;/* 侧边栏内部内容居中(Logo、文字等) */
23+
padding: 20px; /* 侧边栏内边距,提升内部内容美观度 */
24+
border-radius: 8px;/* 圆角设计,和主题风格统一 */
25+
/* 兼容深色模式:使用透明背景 + 主题边框色,避免和深色背景冲突 */
26+
background-color: var(--color-bg-sidebar, rgba(248, 248, 248, 0.8));
27+
border: 1px solid var(--color-border, #eaeaea);
28+
/* 主题兼容性:继承父级字体样式,不强行覆盖 */
29+
font-family: inherit;
30+
font-size: inherit;
31+
}
32+
33+
/* 2.1 侧边栏 Logo 样式 - 精准控制,避免覆盖主题图片 */
34+
.ty-blog-sidebar__logo {
35+
max-width: 160px; /* Logo 最大宽度,防止过大 */
36+
height: auto; /* 保持图片宽高比,避免变形 */
37+
margin: 0 auto 15px; /* 底部间距,和下方文字分隔 */
38+
display: block; /* 确保 margin: 0 auto 生效 */
39+
}
40+
41+
/* 2.2 侧边栏文字/链接样式 - 兼容主题颜色,避免冲突 */
42+
.ty-blog-sidebar__title,
43+
.ty-blog-sidebar__desc,
44+
.ty-blog-sidebar__link {
45+
margin-bottom: 12px;
46+
color: var(--color-text, #333); /* 文字颜色使用 CSS 变量,兼容深色模式 */
47+
text-decoration: none; /* 去除链接默认下划线(可选,保持主题风格) */
48+
}
49+
50+
.ty-blog-sidebar__link:hover {
51+
color: var(--color-link-hover, #0366d6); /* hover 颜色继承主题,提升兼容性 */
52+
text-decoration: underline;
53+
}
54+
55+
/* 2.3 侧边栏下载按钮列表 - 精准类名,避免覆盖全局 ul */
56+
.ty-blog-sidebar__downloads {
57+
list-style: none; /* 去除默认列表圆点 */
58+
padding: 0; /* 去除默认内边距 */
59+
margin: 20px 0 0; /* 顶部间距,和上方内容分隔 */
60+
}
61+
62+
.ty-blog-sidebar__downloads li {
63+
margin-bottom: 8px; /* 按钮之间的间距 */
64+
}
65+
66+
/* 3. 右侧文章内容区 - 精准类名(ty-blog-content) */
67+
.ty-blog-content {
68+
flex: 1; /* 占据剩余所有宽度,自适应布局 */
69+
max-width: 850px; /* 内容区最大宽度,保证阅读体验(避免大屏文字过宽) */
70+
margin: 0 auto; /* 内容区自身水平居中,满足你的核心需求 */
71+
padding: 10px 0; /* 上下内边距,避免内容贴边 */
72+
box-sizing: border-box;
73+
}
74+
75+
/* 3.1 文章内容排版优化 - 兼容主题,提升阅读体验 */
76+
.ty-blog-content h1,
77+
.ty-blog-content h2,
78+
.ty-blog-content h3 {
79+
margin-top: 25px;
80+
margin-bottom: 15px;
81+
color: var(--color-text-heading, #222); /* 标题颜色使用 CSS 变量 */
82+
}
83+
84+
.ty-blog-content p {
85+
line-height: 1.7;
86+
margin-bottom: 15px;
87+
color: var(--color-text, #333);
88+
}
89+
90+
/* 4. 页脚优化 - 独立类名(ty-blog-footer),位置合理 */
91+
.ty-blog-footer {
92+
/* 关键:跟随内容区,放在文章底部,且跨列居中 */
93+
width: 100%;
94+
margin-top: 40px; /* 和文章内容保持足够间距,避免拥挤 */
95+
padding-top: 20px; /* 顶部内边距,搭配边框提升美观 */
96+
border-top: 1px solid var(--color-border, #eaeaea); /* 顶部边框,分隔内容和页脚 */
97+
font-size: 14px;
98+
color: var(--color-text-secondary, #666); /* 次要文字颜色,兼容深色模式 */
99+
text-align: center; /* 页脚文字居中,符合用户习惯 */
100+
/* 防止页脚和内容区重叠 */
101+
clear: both;
102+
}
103+
104+
/* 5. 深色模式兼容 - 核心:使用 CSS 变量 + 主题深色模式钩子 */
105+
/* 5.1 先定义默认(浅色模式)CSS 变量,供全局使用 */
106+
:root {
107+
/* 背景色 */
108+
--color-bg-sidebar: rgba(248, 248, 248, 0.8);
109+
/* 边框色 */
110+
--color-border: #eaeaea;
111+
/* 文字色 */
112+
--color-text: #333;
113+
--color-text-heading: #222;
114+
--color-text-secondary: #666;
115+
/* 链接色 */
116+
--color-link-hover: #0366d6;
117+
}
118+
119+
/* 5.2 兼容 Jekyll 主题深色模式(大部分主题使用 .dark 类或 @media (prefers-color-scheme: dark)) */
120+
/* 方案1:兼容系统深色模式(全局) */
121+
@media (prefers-color-scheme: dark) {
122+
:root {
123+
--color-bg-sidebar: rgba(30, 30, 30, 0.8);
124+
--color-border: #333;
125+
--color-text: #eaeaea;
126+
--color-text-heading: #fff;
127+
--color-text-secondary: #aaa;
128+
--color-link-hover: #4eaaff;
129+
}
130+
}
131+
132+
/* 方案2:兼容主题自定义 .dark 类(部分 Jekyll 主题自带) */
133+
.dark .ty-blog-container,
134+
.dark .ty-blog-sidebar,
135+
.dark .ty-blog-content {
136+
--color-bg-sidebar: rgba(30, 30, 30, 0.8);
137+
--color-border: #333;
138+
--color-text: #eaeaea;
139+
--color-text-heading: #fff;
140+
--color-text-secondary: #aaa;
141+
--color-link-hover: #4eaaff;
142+
}
143+
144+
/* 6. 响应式适配 - 手机端自动变回上下布局,兼容移动端 */
145+
@media (max-width: 768px) {
146+
.ty-blog-container {
147+
flex-direction: column; /* 手机端:上下排列,避免拥挤 */
148+
gap: 30px; /* 上下间距缩小,更适配移动端 */
149+
padding: 20px 15px;
150+
}
151+
152+
.ty-blog-sidebar {
153+
width: 100%; /* 侧边栏占满屏幕宽度 */
154+
margin-bottom: 0; /* 配合 gap,无需额外间距 */
155+
}
156+
157+
.ty-blog-content {
158+
max-width: 100%; /* 移动端内容区占满宽度 */
159+
}
160+
161+
.ty-blog-footer {
162+
margin-top: 30px; /* 移动端页脚间距适当缩小 */
163+
}
164+
}

‎assets/css/style.scss‎

Whitespace-only changes.

0 commit comments

Comments
 (0)