主题定制指南

定制; CSS; Tailwind 341 字 2 min read

本文介绍如何定制 astro-koharu 的外观和样式。

分类说明

本文已归档到“示例”分类,便于集中浏览主题内置文档:

  • URL: /categories/examples
  • 面包屑: 示例

在 frontmatter 中这样配置:

categories:
  - 示例

配色定制

CSS 变量

主题颜色通过 CSS 变量定义,位于 src/styles/index.css

:root {
  --primary-color: #ff6b9d;
  --secondary-color: #7dd3fc;
  /* ...更多变量 */
}

.dark {
  --primary-color: #f472b6;
  --secondary-color: #38bdf8;
}

Tailwind 配置

编辑 tailwind.config.ts 自定义主题:

export default {
  theme: {
    extend: {
      colors: {
        primary: 'var(--primary-color)',
        secondary: 'var(--secondary-color)',
      },
    },
  },
};

布局调整

内容宽度

src/constants/layout.ts 中调整布局常量:

export const LAYOUT = {
  maxWidth: '1200px',
  sidebarWidth: '300px',
  contentPadding: '1.5rem',
};

响应式断点

主题使用 Tailwind 的默认断点:

断点宽度用途
sm640px小型手机
md768px平板
lg1024px桌面
xl1280px大屏幕

动画效果

Motion 配置

动画使用 Motion 库,配置位于 src/constants/anim/

// spring.ts - 弹簧动画
export const springConfig = {
  stiffness: 100,
  damping: 10,
};

// variants.ts - 动画变体
export const fadeIn = {
  hidden: { opacity: 0 },
  visible: { opacity: 1 },
};

禁用动画

对于偏好减少动画的用户,主题会自动响应 prefers-reduced-motion 媒体查询。

总结

通过修改以上配置,你可以轻松打造属于自己风格的博客。如有问题,欢迎在 GitHub 提 Issue。