mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-12-06 06:16:06 +08:00
fix(mathjax): cover all block containers for inline formula overflow
Once mjx-container is forced to display: inline, its own max-width and overflow-x no longer apply to a non-replaced inline box, so the formula width escapes to the document. The previous rule only covered p and li. - cover headings (h1-h6) too, otherwise a long inline formula in a heading widens the page (measured 395px of horizontal page scroll at a 420px viewport) - li becomes a scroll container, which clips its outside-positioned ::marker, so switch those items to list-style-position: inside - fall back to the previous inline-grid when :has() is unsupported, since the container rules are then dropped while display: inline still applies, which is worse than before
This commit is contained in:
1 parent
f5a043e38e
commit
ae09618131
1 file changed
+23
-5
@@ -288,17 +288,35 @@ if hexo-config('math.use')
|
||||
display: block !important
|
||||
min-width: auto !important
|
||||
|
||||
// MathJax 4 会把一条行内公式拆成多个 <svg> + <mjx-break>,
|
||||
// 只有内联排版能保留段间距和每段自己的 vertical-align,
|
||||
// 用 nowrap 保证它不换行,超长时交给外层段落横向滚动
|
||||
// MathJax 4 splits an inline formula into several <svg> + <mjx-break>.
|
||||
// Inline layout keeps the line spacing and each part's vertical-align,
|
||||
// and nowrap keeps these parts on one line.
|
||||
&:not([display])
|
||||
display: inline !important
|
||||
white-space: nowrap
|
||||
|
||||
// 行内公式过长时让所在段落/列表项横向滚动,而不是撑破页面
|
||||
#article-container :is(p, li):has(mjx-container:not([display]))
|
||||
// Let the block-level parent scroll instead of overflowing the page.
|
||||
// p / li alone is not enough: headings and note bodies overflow too,
|
||||
// because max-width no longer applies once mjx-container is inline.
|
||||
#article-container :is(p, h1, h2, h3, h4, h5, h6):has(mjx-container:not([display]))
|
||||
overflow-x: auto
|
||||
|
||||
// A scrolling li clips its outside-positioned ::marker.
|
||||
#article-container li:has(mjx-container:not([display]))
|
||||
overflow-x: auto
|
||||
list-style-position: inside
|
||||
|
||||
// Without :has() the rules above are dropped while inline still applies.
|
||||
// Fall back to the previous inline-grid rather than an unclipped inline.
|
||||
@css {
|
||||
@supports not selector(:has(a)) {
|
||||
mjx-container:not([display]) {
|
||||
display: inline-grid !important;
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mjx-assistive-mml
|
||||
right: 0
|
||||
bottom: 0
|
||||
|
||||
Reference in new issue
Block a user