Repository navigation
|
Hi all! I have a question about css selectors: I like serif fonts, so I'd started to write a custom style which changes every fonts on every webpage to serif. However there are some exceptions, notably:
I can override all fonts like this: body :not(code):not(pre) {font-family: serif !important;}but what should really there is to set font to serif for all places except Thanks |
Replies: 2 comments 7 replies
Since I also prefer serif fonts, I made the following userstyle for my own use. It uses Stylus-lang preprocessor in order for code to be more documented, extendable, and maintainable in the long run. /* ==UserStyle==
@name Global serif font
@namespace www
@version 1.0.0
@description Apply your favorite serif font globally.
@author vednoc
@preprocessor stylus
@var text font 'Serif font' '"your favorite serif font"'
==/UserStyle== */
@-moz-document regexp("https?://.*") {
i = !important
// Exclude default code areas.
n ?= ':not(code):not(pre):not(pre > span):not(code > span)'
// Exclude icon fonts.
n += ':not([class^="fa"]):not(.i)'
// Exclude code areas on GitHub.
n += ':not([class^="blob-"]):not([class^="blob-"] > span)'
// Exclude code areas on GitLab.
n += ':not(.diff-line-num):not(pre > code > span span)'
// Exclude utility classes for fonts.
n += ':not(.monospace):not(.text-mono)'
// Generate.
{ n } {
font-family: font, serif i
}
}For more information, check wiki pages on how to install it and then customize it if you've never used UserCSS format until now.
As far as I know, this is the only way to do it. :not(pre):not(pre *):not(code):not(code *) { ... } |
|
I see I'm late to the party, and this note may be somewhat tangential, but do you know that our browsers are practically obliged to have pref for this? In Firefox,
So in this case there is no "external" tool necessary for your specific need, and it is covered in the best possible way: when page author orders something to use the In Chromium, somewhat unsurprisingly, things are not that easy. While you still can change your defaults (through but with boosted specificity, whitelist for icon fonts (if really needed) and "fixes" of unsuitable UA style's "defaults". In a (literal) mock-up form: *:not(
#just#boosting#specificity#and#yearning#for#true#userstyles#la#la#la, /* (Self-explanatory.) */
.some, .whitelist, .for, [class*="icon"], .fonts, .like, [class|="fa"] /* (Dtto.) */
){
&, &::before, &::after {
font-family: revert !important;
/* Use what our default UA style orders - so in effect our prefs for most tags. */
}
&:is(
input, textarea, pre *, code *,
[class|="CodeBlob"] * /* GH*/, [class*="code" i] * /* Or even broader? */
/* Etc etc. */
/* Thingies other than PRE we'd like to have monospaced but UA style has them proportional. */
) {
font-family: monospace !important;
}
}This is functionally close to Vendoc's style, minus sophisticated whitelist and granular settings for weights, but leaning on browser settings instead of style prefs. * This always was, FMPoV, a bit controversial decision, but now I see better it makes sense in some scenarios. Technically it works in a way that any font with a specific internal name (currently |

Since I also prefer serif fonts, I made the following userstyle for my own use. It uses Stylus-lang preprocessor in order for code to be more documented, extendable, and maintainable in the long run.