/* ============================================ Phone Image Template System 用于生成手机端分享图片的CSS框架 渲染宽度540px, html2canvas scale=2 输出1080px 注意: 仅使用html2canvas兼容的CSS属性 支持: flexbox, border-radius, box-shadow, background-color, font, padding, margin, border, position(relative/absolute/fixed) 不支持: transform, filter, clip-path, backdrop-filter, CSS grid, object-fit, position:sticky, CSS animations ============================================ */ /* --- CSS Custom Properties --- */ :root { /* 字号 */ --pi-font-size-base: 14px; --pi-font-size-title: 24px; --pi-font-size-subtitle: 16px; --pi-font-size-small: 12px; /* 行高 */ --pi-line-height: 1.8; /* 间距 */ --pi-spacing: 20px; --pi-spacing-sm: 10px; --pi-spacing-lg: 30px; /* 颜色 */ --pi-color-text: #333333; --pi-color-text-light: #666666; --pi-color-text-lighter: #999999; --pi-color-bg: #ffffff; --pi-color-accent: #1890ff; --pi-color-border: #eeeeee; /* 字体 */ --pi-font-family: 'Source Han Sans', 'SourceHanSans-Normal', sans-serif; } /* ============================================ Base Container 固定540px宽度的最外层容器 ============================================ */ .phone-image-container { width: 540px; background: var(--pi-color-bg); color: var(--pi-color-text); font-family: var(--pi-font-family); font-size: var(--pi-font-size-base); line-height: var(--pi-line-height); overflow: hidden; position: relative; } /* ============================================ Page Container 每一页的容器, 尺寸由 size class 控制 ============================================ */ .phone-image-page { overflow: hidden; box-sizing: border-box; position: relative; } /* ============================================ Size Variants 两种主流手机图片尺寸 ============================================ */ /* 小红书尺寸 540x720 (输出1080x1440) */ .size-xiaohongshu .phone-image-page { width: 540px; height: 720px; } /* 抖音尺寸 540x960 (输出1080x1920) */ .size-douyin .phone-image-page { width: 540px; height: 960px; } /* ============================================ Page Type Variants 三种页面类型: 封面页/内容页/总结页 ============================================ */ /* --- 封面页/首页 --- */ .page-cover { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: var(--pi-spacing-lg); text-align: center; } .page-cover .cover-title { font-size: 32px; font-weight: bold; line-height: 1.4; margin-bottom: var(--pi-spacing); color: var(--pi-color-text); word-break: break-word; } .page-cover .cover-subtitle { font-size: var(--pi-font-size-subtitle); color: var(--pi-color-text-light); margin-bottom: var(--pi-spacing); } .page-cover .cover-image { width: 100%; margin-bottom: var(--pi-spacing); } .page-cover .cover-meta { font-size: var(--pi-font-size-small); color: var(--pi-color-text-lighter); margin-top: var(--pi-spacing-sm); } /* --- 封面页 - 无封面图装饰排版 --- */ .page-cover.no-cover-image { justify-content: center; padding: var(--pi-spacing-lg); } .page-cover.no-cover-image .cover-decor-line { position: absolute; left: 30px; right: 30px; height: 2px; background: var(--pi-color-border); } .page-cover.no-cover-image .cover-decor-top { top: 80px; } .page-cover.no-cover-image .cover-decor-bottom { bottom: 80px; } .page-cover.no-cover-image .cover-no-img-content { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--pi-spacing) 0; } .page-cover.no-cover-image .cover-no-img-title { font-size: 36px; font-weight: bold; line-height: 1.4; color: var(--pi-color-text); word-break: break-word; margin-bottom: var(--pi-spacing); padding: 0 20px; } .page-cover.no-cover-image .cover-decor-divider { width: 60px; height: 3px; background: var(--pi-color-accent); margin-bottom: var(--pi-spacing); } .page-cover.no-cover-image .cover-no-img-desc { font-size: var(--pi-font-size-subtitle); color: var(--pi-color-text-light); line-height: 1.8; margin-bottom: var(--pi-spacing); padding: 0 30px; word-break: break-word; } .page-cover.no-cover-image .cover-no-img-meta { display: flex; gap: 15px; font-size: var(--pi-font-size-small); color: var(--pi-color-text-lighter); flex-wrap: wrap; justify-content: center; } /* --- 内容页图片强制约束 --- */ .page-content img { max-width: 100% !important; height: auto !important; display: block; margin: 10px 0; } /* --- 内容页 --- */ .page-body { display: flex; flex-direction: column; padding: var(--pi-spacing); } /* 内容页 - 页头区域 */ .page-header { padding-bottom: var(--pi-spacing-sm); margin-bottom: var(--pi-spacing); border-bottom: 1px solid var(--pi-color-border); } .page-header .page-title { font-size: var(--pi-font-size-title); font-weight: bold; line-height: 1.4; color: var(--pi-color-text); word-break: break-word; } .page-header .page-subtitle { font-size: var(--pi-font-size-subtitle); color: var(--pi-color-text-light); margin-top: var(--pi-spacing-sm); } /* 内容页 - 正文区域 */ .page-content { flex: 1; overflow: hidden; word-break: break-word; } .page-content p { margin-bottom: var(--pi-spacing-sm); text-indent: 2em; } .page-content h2 { font-size: 20px; font-weight: bold; margin-top: var(--pi-spacing); margin-bottom: var(--pi-spacing-sm); } .page-content h3 { font-size: var(--pi-font-size-subtitle); font-weight: bold; margin-top: var(--pi-spacing-sm); margin-bottom: var(--pi-spacing-sm); } .page-content h4 { font-size: var(--pi-font-size-base); font-weight: bold; margin-top: var(--pi-spacing-sm); margin-bottom: 5px; } .page-content h5 { font-size: 13px; font-weight: bold; margin-top: var(--pi-spacing-sm); margin-bottom: 5px; } .page-content h6 { font-size: 12px; font-weight: bold; margin-top: var(--pi-spacing-sm); margin-bottom: 5px; color: var(--pi-color-text-light); } .page-content blockquote { border-left: 3px solid var(--pi-color-accent); padding-left: var(--pi-spacing-sm); margin: var(--pi-spacing-sm) 0; color: var(--pi-color-text-light); font-style: italic; } .page-content ul, .page-content ol { padding-left: var(--pi-spacing); margin-bottom: var(--pi-spacing-sm); } .page-content li { margin-bottom: 5px; } /* 内容页 - 页脚区域 */ .page-footer { padding-top: var(--pi-spacing-sm); margin-top: var(--pi-spacing-sm); border-top: 1px solid var(--pi-color-border); font-size: var(--pi-font-size-small); color: var(--pi-color-text-lighter); display: flex; justify-content: space-between; align-items: center; } /* --- 总结页/尾页 --- */ .page-summary { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: var(--pi-spacing-lg); text-align: center; } .page-summary .summary-title { font-size: var(--pi-font-size-title); font-weight: bold; margin-bottom: var(--pi-spacing); color: var(--pi-color-text); } .page-summary .summary-text { font-size: var(--pi-font-size-subtitle); color: var(--pi-color-text-light); margin-bottom: var(--pi-spacing); line-height: 1.6; } .page-summary .summary-qr { margin-bottom: var(--pi-spacing-sm); } .page-summary .summary-footer { font-size: var(--pi-font-size-small); color: var(--pi-color-text-lighter); } /* ============================================ Font Variants 三种可选字体 ============================================ */ .font-source-han-sans { --pi-font-family: 'Source Han Sans', 'SourceHanSans-Normal', sans-serif; } .font-alibaba-puhuiti { --pi-font-family: 'AlibabaPuHuiTi', sans-serif; } .font-lxgw-wenkai { --pi-font-family: 'LXGWWenKai', cursive; } /* ============================================ Article Images 文章内图片样式 ============================================ */ /* 行内图片, 有边距 */ .article-image { max-width: 100%; height: auto; display: block; margin: var(--pi-spacing) 0; } /* 全宽图片, 无边距 */ .article-image-full { width: 100%; height: auto; display: block; margin: 0; } /* ============================================ Page Number 页码指示器 ============================================ */ .page-number { position: absolute; bottom: 10px; right: 15px; font-size: var(--pi-font-size-small); color: var(--pi-color-text-lighter); } /* ============================================ Template Namespaces 三个模板命名空间, 基础结构样式 后续Task 8-10会填充详细样式 ============================================ */ /* --- 简约文字卡片模板 --- */ .tpl-minimal { /* 基础结构: 白底黑字, 大量留白, 现代简约风格 */ } /* 封面页 - 居中大标题 + 副标题 + 日期 */ .tpl-minimal .page-cover .cover-title { font-size: 28px; font-weight: normal; letter-spacing: 2px; line-height: 1.5; } .tpl-minimal .page-cover .cover-subtitle { font-weight: normal; letter-spacing: 1px; color: #999; } .tpl-minimal .page-cover .cover-meta { letter-spacing: 1px; } /* 内容页 - 页头区域 */ .tpl-minimal .page-header { border-bottom: none; padding-bottom: 0; margin-bottom: 20px; } .tpl-minimal .page-header .page-title { font-size: 20px; font-weight: normal; letter-spacing: 1px; color: #666; } /* 内容页 - 正文区域: 宽行高(2.0), 大段落间距, 首行缩进2em */ .tpl-minimal .page-content { line-height: 2.0; } .tpl-minimal .page-content p { text-indent: 2em; margin-bottom: 16px; color: #333; } .tpl-minimal .page-content h2 { font-weight: normal; font-size: 18px; letter-spacing: 1px; margin-top: 24px; margin-bottom: 12px; color: #333; } .tpl-minimal .page-content h3 { font-weight: normal; font-size: 16px; margin-top: 20px; margin-bottom: 10px; color: #555; } .tpl-minimal .page-content blockquote { border-left: 1px solid #ccc; font-style: normal; color: #888; padding-left: 15px; } .tpl-minimal .page-content .article-image { border-radius: 4px; } .tpl-minimal .page-content .article-image-full { border-radius: 0; } /* 内容页 - 页脚区域: 小号版权 + 页码, 细线分隔 */ .tpl-minimal .page-footer { border-top: none; padding-top: 0; font-size: 11px; color: #bbb; } /* 总结页/尾页 */ .tpl-minimal .page-summary .summary-title { font-weight: normal; letter-spacing: 2px; font-size: 22px; } .tpl-minimal .page-summary .summary-text { color: #aaa; font-weight: normal; } .tpl-minimal .page-summary .summary-footer { color: #ccc; } /* --- 杂志模板 - 完整样式 --- */ .tpl-magazine .page-cover { padding: 0; justify-content: flex-end; padding-bottom: 40px; position: relative; } .tpl-magazine .page-cover::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 4px; background: #1890ff; } .tpl-magazine .page-cover .cover-title { font-size: 26px; font-weight: bold; line-height: 1.4; letter-spacing: 1px; position: relative; padding-bottom: 15px; } .tpl-magazine .page-cover .cover-subtitle { font-weight: normal; color: #666; letter-spacing: 0.5px; } .tpl-magazine .page-cover .cover-meta { position: relative; padding: 8px 12px; background: #f5f5f5; border-radius: 2px; } .tpl-magazine .page-header { border-bottom: 2px solid #1890ff; padding-bottom: 10px; margin-bottom: 15px; } .tpl-magazine .page-header .page-title { font-size: 22px; font-weight: bold; letter-spacing: 0.5px; } .tpl-magazine .page-content { line-height: 1.8; } .tpl-magazine .page-content p { margin-bottom: 14px; text-indent: 2em; color: #333; } .tpl-magazine .page-content p:first-child { text-indent: 0; } .tpl-magazine .page-content p:first-child::first-letter { font-size: 3.2em; font-weight: bold; float: left; line-height: 1; margin-right: 8px; margin-top: 4px; color: #1890ff; } .tpl-magazine .page-content h2 { font-size: 20px; font-weight: bold; margin-top: 22px; margin-bottom: 10px; padding-left: 10px; border-left: 3px solid #1890ff; } .tpl-magazine .page-content h3 { font-size: 17px; font-weight: bold; margin-top: 16px; margin-bottom: 8px; color: #1890ff; } .tpl-magazine .page-content blockquote { border-left: 4px solid #1890ff; background: #f8f9fa; padding: 12px 15px; margin: 12px 0; font-style: normal; color: #555; border-radius: 0 4px 4px 0; } .tpl-magazine .page-content .article-image { border-radius: 2px; } .tpl-magazine .page-footer { border-top: 2px solid #1890ff; padding-top: 8px; color: #1890ff; font-weight: bold; } .tpl-magazine .page-summary { background: #f8f9fa; } .tpl-magazine .page-summary .summary-title { color: #1890ff; font-size: 24px; font-weight: bold; } .tpl-magazine .page-summary .summary-text { color: #666; } .tpl-magazine .page-summary .summary-footer { border-top: 1px solid #ddd; padding-top: 15px; color: #999; } /* --- 图文混排模板 - 完整样式 --- */ .tpl-mixed { /* 基础结构: 图文混排 */ } /* 封面页: 图片背景 + 底部文字叠加 */ .tpl-mixed .page-cover { justify-content: flex-end; padding: 0; padding-bottom: 30px; position: relative; } .tpl-mixed .page-cover .cover-image { position: absolute; top: 0; left: 0; width: 100%; height: 100%; } .tpl-mixed .page-cover .cover-title { position: relative; z-index: 2; font-size: 24px; font-weight: bold; line-height: 1.4; color: #fff; background: rgba(0, 0, 0, 0.5); padding: 15px 20px; width: 100%; box-sizing: border-box; text-align: left; } .tpl-mixed .page-cover .cover-subtitle { position: relative; z-index: 2; color: #eee; background: rgba(0, 0, 0, 0.3); padding: 8px 20px; width: 100%; box-sizing: border-box; text-align: left; margin-bottom: 0; } .tpl-mixed .page-cover .cover-meta { position: relative; z-index: 2; color: #ccc; padding: 5px 20px; background: rgba(0, 0, 0, 0.3); width: 100%; box-sizing: border-box; text-align: left; } /* 无封面图时的降级样式 */ .tpl-mixed .page-cover.no-cover-image { justify-content: center; background: #333; } .tpl-mixed .page-cover.no-cover-image .cover-title { text-align: center; background: none; font-size: 26px; } .tpl-mixed .page-cover.no-cover-image .cover-subtitle { text-align: center; background: none; } .tpl-mixed .page-cover.no-cover-image .cover-meta { text-align: center; background: none; } /* 内容页头部 */ .tpl-mixed .page-header { border-bottom: 2px solid #333; padding-bottom: 8px; } .tpl-mixed .page-header .page-title { font-size: 20px; font-weight: bold; } /* 内容页正文 */ .tpl-mixed .page-content { line-height: 1.8; } .tpl-mixed .page-content p { margin-bottom: 12px; text-indent: 2em; color: #333; } .tpl-mixed .page-content h2 { font-size: 19px; font-weight: bold; margin-top: 18px; margin-bottom: 8px; padding: 6px 12px; background: #f0f0f0; border-left: 4px solid #333; } .tpl-mixed .page-content h3 { font-size: 16px; font-weight: bold; margin-top: 14px; margin-bottom: 6px; color: #555; } .tpl-mixed .page-content blockquote { border-left: 3px solid #333; background: #f8f8f8; padding: 10px 15px; font-style: normal; color: #666; } .tpl-mixed .page-content .article-image { border-radius: 0; margin: 15px 0; } .tpl-mixed .page-content .article-image-full { margin: 0 -20px; max-width: none; width: 540px; } /* 内容页底部 */ .tpl-mixed .page-footer { border-top: 1px solid #333; color: #333; font-weight: bold; } /* 总结页 */ .tpl-mixed .page-summary { background: #f5f5f5; } .tpl-mixed .page-summary .summary-title { font-size: 28px; font-weight: bold; color: #333; } .tpl-mixed .page-summary .summary-text { color: #666; } .tpl-mixed .page-summary .summary-footer { color: #999; border-top: 1px solid #ddd; padding-top: 15px; }