From 488a2427874c3492883c5af19b45ef63cb73e4c1 Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Fri, 19 Sep 2025 19:10:37 +0800 Subject: [PATCH] css: default to lower font-family specificity than the styles defined inside the ebook, closes #2070 (#2081) --- apps/readest-app/src/utils/style.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/readest-app/src/utils/style.ts b/apps/readest-app/src/utils/style.ts index 76b0d91c..bcc6a7c8 100644 --- a/apps/readest-app/src/utils/style.ts +++ b/apps/readest-app/src/utils/style.ts @@ -48,6 +48,7 @@ const getFontStyles = ( ...FALLBACK_FONTS, ]; const monospaceFonts = [monospace, ...MONOSPACE_FONTS.filter((font) => font !== monospace)]; + const defaultFontFamily = defaultFont.toLowerCase() === 'serif' ? '--serif' : '--sans-serif'; const fontStyles = ` html { --serif: ${serifFonts.map((font) => `"${font}"`).join(', ')}, serif; @@ -55,12 +56,19 @@ const getFontStyles = ( --monospace: ${monospaceFonts.map((font) => `"${font}"`).join(', ')}, monospace; } html, body { - font-family: var(${defaultFont.toLowerCase() === 'serif' ? '--serif' : '--sans-serif'}) ${overrideFont ? '!important' : ''}; font-size: ${fontSize}px !important; font-weight: ${fontWeight}; -webkit-text-size-adjust: none; text-size-adjust: none; } + /* lower specificity than ebook built-in font styles */ + html { + font-family: var(${defaultFontFamily}) ${overrideFont ? '!important' : ''}; + } + /* higher specificity than ebook built-in font styles */ + html body { + ${overrideFont ? `font-family: var(${defaultFontFamily}) !important;` : ''} + } font[size="1"] { font-size: ${minFontSize}px; }