-
Notifications
You must be signed in to change notification settings - Fork 56
fix: 修复移动端代码块横向滚动崩坏问题 #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cf4e559
cc9bb93
a1535af
4185e93
a36ddd9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -413,35 +413,43 @@ | |
| background: oklch(0.15 0.006 220) !important; | ||
| border: 1px solid oklch(1 0 0 / 6%); | ||
| overflow-x: auto; | ||
| -webkit-overflow-scrolling: touch; /* iOS 惯性滚动 */ | ||
| } | ||
|
|
||
| .prose-monolith .code-block-wrapper pre { | ||
| margin: 0; | ||
| padding: 16px 20px; | ||
| padding: 14px 24px; | ||
| border-radius: 0; | ||
| border: none; | ||
| /* 不在 pre 层裁剪,由 wrapper 统一负责横向滚动 */ | ||
| overflow-x: visible; | ||
| /* 强制不换行,让内容真实撑开 wrapper */ | ||
| white-space: pre; | ||
| font-size: 13px; | ||
| line-height: 1.85; | ||
| letter-spacing: 0; | ||
| font-family: ui-monospace, "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace; | ||
| } | ||
|
|
||
| /* 移动端代码块右侧留白增强 */ | ||
| @media (max-width: 768px) { | ||
| .prose-monolith .code-block-wrapper pre { | ||
| padding-right: 24px; | ||
| padding: 12px 16px; | ||
| /* 移动端:确保 pre 宽度可以超出 wrapper,由 wrapper 滚动 */ | ||
| width: max-content; | ||
| min-width: 100%; | ||
| } | ||
| } | ||
|
|
||
| /* 独立 pre 兜底样式(不在 code-block-wrapper 内时) */ | ||
| .prose-monolith pre:not(.hljs) { | ||
| margin: 24px 0; | ||
| padding: 16px 20px; | ||
| padding: 14px 24px; | ||
| border-radius: 8px; | ||
| background: oklch(0.15 0.006 220) !important; | ||
| border: 1px solid oklch(1 0 0 / 6%); | ||
| overflow-x: auto; | ||
| -webkit-overflow-scrolling: touch; /* iOS 惯性滚动 */ | ||
| white-space: pre; /* 强制不换行 */ | ||
| font-size: 13px; | ||
| line-height: 1.85; | ||
| letter-spacing: 0; | ||
|
|
@@ -650,17 +658,17 @@ | |
| /* 代码行布局 */ | ||
| .prose-monolith pre code .code-line { | ||
| display: inline-block; | ||
| min-width: 100%; | ||
| padding: 0 4px; | ||
| margin: 0 -4px; | ||
| border-radius: 2px; | ||
| /* min-width 由 code 元素的 white-space:pre 自然撑开,不在此设置避免循环依赖 */ | ||
| } | ||
|
Comment on lines
659
to
665
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # 首先查看globals.css文件的662-671行及周围上下文
cat -n client/src/globals.css | sed -n '655,680p'Repository: one-ea/Monolith Length of output: 817 🏁 Script executed: # 搜索相关的选择器定义
rg -n "\.code-line|\.line-highlight|\.diff-add|\.diff-del" client/src/globals.css -B2 -A2Repository: one-ea/Monolith Length of output: 1484 🏁 Script executed: # 查找主题变量定义
rg -n "\[data-theme|--.*-bg|--.*-highlight" client/src/globals.css | head -20Repository: one-ea/Monolith Length of output: 1377 🏁 Script executed: # 搜索所有包含 .code-line 的选择器定义
rg -n "\.code-line" client/src/globals.css -A3Repository: one-ea/Monolith Length of output: 350 🏁 Script executed: # 检查是否有其他暗色主题下但未在亮色主题中定义的选择器
rg -n "\.prose-monolith pre code" client/src/globals.css | grep -v "data-theme" | head -30Repository: one-ea/Monolith Length of output: 304 🏁 Script executed: # 检查亮色主题下 .prose-monolith pre code 相关的所有定义
rg -n "\[data-theme=\"light\"\].*\.prose-monolith.*code" client/src/globals.css -A2Repository: one-ea/Monolith Length of output: 2197
从 如需统一对齐到最宽行,可考虑在父级 亮色主题的高亮颜色( 🤖 Prompt for AI Agents |
||
|
|
||
| /* 行号 */ | ||
| .prose-monolith pre code .line-number { | ||
| display: inline-block; | ||
| width: 32px; | ||
| margin-right: 16px; | ||
| width: 28px; | ||
| margin-right: 12px; | ||
| text-align: right; | ||
| color: oklch(0.35 0 0); | ||
| user-select: none; | ||
|
|
@@ -678,7 +686,7 @@ | |
|
|
||
| /* 有行号时调整 pre 左边距 */ | ||
| .prose-monolith .has-line-numbers pre { | ||
| padding-left: 16px; | ||
| padding-left: 12px; | ||
| } | ||
|
|
||
| /* 高亮行 */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
滚动末端右内边距丢失的潜在视觉问题
.code-block-wrapper负责横向滚动,而子pre设置了padding: 14px 24px(移动端12px 16px)。由于内部code的width: max-content会让内容溢出pre,滚动容器是 wrapper,滚到最右端时pre的右内边距不会跟随内容出现在视口末尾——末行右侧会紧贴 wrapper 边缘,缺少 24px/16px 的呼吸空间。这是overflow-x: auto容器 + 内部盒padding的经典问题。如果希望右侧保留一致的留白,可以把横向 padding 从
pre移到 wrapper,或者在code上使用padding-right/box-shadow兜住末端。示意:♻️ 一种可选修正(任选其一即可)
.prose-monolith .code-block-wrapper pre { margin: 0; - padding: 14px 24px; + padding: 14px 0; ... } +.prose-monolith .code-block-wrapper pre code { + padding-right: 24px; +}桌面端与亮/暗色模式下行为一致,不影响主题变量配对。可按需采用。
🤖 Prompt for AI Agents