#Body vs Heading Fonts

208 messages · Page 1 of 1 (latest)

mellow lark
#

In Common.css, I am trying to edit my body and heading fonts separately. I have tried to search for existing posts on here to find out how. However I'm not sure why this isn't working.

Question: How exactly do you call the 'body' font vs 'firstheading' font and so on in Common.css?

sour salmon
#

I don't think that's how you import fonts from Google Fonts

mellow lark
#

it seemed to work before, it did pull through Lora

#

it's the import embed code

sour salmon
#

Those font URLs don't point to fonts, they point to plain CSS files

#

Can you link to the wiki

mellow lark
#

Uh every time I do it says people can't access it because its private

#

this page should be whitelisted

#

The issue I'm having is then

1. Apparently I don't know what embed/import code to use from Google Fonts

2. I don't know how to refer to each level of font (body, heading 1, heading 2, etc.) in the common.css

sour salmon
#

Just use @import url("https://fonts.googleapis.com/css?family=Lora|Nunito&display=swap"); instead of those font-face declarations

mellow lark
#

So you can import multiple within the same font-face?

#

just separate them with a pipe?

sour salmon
#

You can't use @font-face you have to use @import

mellow lark
#

sorry okay, got it

#

and css rather than css2?

sour salmon
#

Yeah idk why css2 doesn't let you import multiple or even what's the difference

#

Like the output CSS looks the same

mellow lark
#

Hmm okay I have changed that but don't see any difference using ?debug=2 on my testing page, or in css common

#

do the mw-body content bits need changing

sour salmon
#

But anyways

mellow lark
#
@import url("https://fonts.googleapis.com/css?family=Lora|Nunito&display=swap");
}
.mw-body-content .firstheading {
    font-family: 'Lora', Serif;
}
.mw-body-content .body {
    font-family: 'Nunito', Sans-Serif;
}
sour salmon
#

Firstly you left that hanging }

#

And secondly the class is firstHeading

mellow lark
#

oh, the capitalisation matters?

sour salmon
#

Yeah

hardy helm
#

is .body a class?

mellow lark
#

so it's a guess

sour salmon
#

Yeah .body is not a class that I know of

mellow lark
#

Do you know what the class for body text would be?

sour salmon
#

You can just use .mw-body-content

hardy helm
#
:root {
  --font-family-citizen-base: Nunito, sans-serif;
}
mellow lark
#

Hm okay I have changed it to that, but it doesn't seem to recognise either of them

#

it's defaulting to whatever the usual font for citizen is

sour salmon
#

Oh yeah I forgot Citizen actually has CSS variables

mellow lark
hardy helm
#

It does for me

mellow lark
#
/* CSS placed here will be applied to all skins */
/* FONTS */
@import url{("https://fonts.googleapis.com/css?family=Lora|Nunito&display=swap");
}
:root {
  --font-family-citizen-base: Nunito, sans-serif;
}
hardy helm
#
@import url("https://fonts.googleapis.com/css?family=Lora|Nunito&display=swap");
:root {
  --font-family-citizen-base: Nunito, sans-serif;
}```
mellow lark
#

oh

#

I didnt

#

sorry

hardy helm
#

The code is "working" but the font is never imported because the syntax is invalid

mellow lark
#

I thought they were meant to be separate

mellow lark
hardy helm
#

No

mellow lark
#

Hm i have copied it over directly to be sure, still no dice

hardy helm
#

Oh I forgot, the URL itself isn't correct

#

One sec

mellow lark
#

this is what google fonts gives me

sour salmon
sour salmon
mellow lark
#

I don't know what the difference between the two is, practically

#

wow

sour salmon
mellow lark
#

ok

#

it works

hardy helm
#
@import url('https://fonts.googleapis.com/css2?family=Lora:wght@600&family=Nunito:ital@0;1&display=swap');
mellow lark
#

but it took 15 mins to even update the debug=2 disabled cache or common css pages

hardy helm
#

so I switched to css2

sour salmon
#

No yeah css2 has a different way to specify families

mellow lark
#
@import url("https://fonts.googleapis.com/css?family=Lora&family=Nunito&display=swap");
:root {
  --font-family-citizen-base: Nunito, sans-serif;
}
#

this is what it looks like now

#

And it recognises the body font

#

Now just need to add in the heading again
Looking at other posts, would it be something like

.mw-body .firstHeading, .mw-body-content h1, .mw-body-content h2, .mw-body-content h3, .mw-body-content h4, .mw-body-content h5, .mw-body-content h6, .mw-heading1, h1, .mw-heading2, h2 {font-family: 'Lora';}

Because I don't know what it would be as the variable (?) Unai made?

hardy helm
#

The variable I posted was specifically for body text

mellow lark
#

would there be a way to make ones for the heading levels, or headings overall, or do they need to be referred to like the above

#

Apologies for being dense

hardy helm
#

You can use that, although I'd go for a cleaner (and safer) way with

#
.mw-heading, .mw-page-title-main {
    font-family: Lora;
}
#

Citizen relies heavily on CSS variables and intends you to use them so you can quickly overwrite stuff without worrying if you used enough selectors or not. That said, you can use normal selectors if you need anything specific. It's just ergonomics.

mellow lark
#

That looks like it has worked for the testing page
All headers are now Lora, all body font (confirmed via Inspect) is Nunito

mellow lark
hardy helm
#

Yup, I recommend checking the Computed tab (if you're on Chrome) to confirm the font has loaded

mellow lark
hardy helm
#

Citizen relies on variables so its design is consistent

#

You can use them, or you can just brute-force your way with normal CSS

#

They do appear in devtools if you want to check them out

mellow lark
#

I think I get that, but I don't understand how one can make an arbitrarily named variable and the system knows how that refers to the body font, for example

hardy helm
#

If you click on that it should scroll to the variable declaration (usually, at :root)

mellow lark
#

unless it isn't arbitrary, the name of the variable?

hardy helm
#

I suggested that variable because, as you can see, the original Citizen CSS refers to --font-family-base, which value is var(--font-family-citizen-base), var(--font-family-language-base), system-ui, -apple-system, sans-serif
And down the rabbit hole, --font-family-citizen-base is 'Roboto', 'Roboto-fallback' (originally), so I overwrote it. I could have overwritten html, body {} or --font-family-base as well, but this path was safer.

hardy helm
mellow lark
#

Ah I think I see
So when you're declaring a variable, it isn't just a random name which you're assigning value to, it's an existing value somewhere in the citizen css that you are changing the value of?

#

oh

#

noted, I'll see if I can use dev tools in future

hardy helm
#

I mean you can declare your own as well

mellow lark
#

that makes much more sense

hardy helm
#

I did that in my wiki using Citizen

#

But yes, Citizen's modern CSS in a way makes it more difficult as you need to be aware of more things

mellow lark
#

It was worth it for the wiki looking like it is from the 2020s without having to change too many things manually

hardy helm
#

For example, this is how I changed colors

#
:root {
  --color-progressive-oklch__l: 26.53%;
  --color-progressive-oklch__c: .0136;
  --color-progressive-oklch__h: 290.72;
  --color-surface-0: #f8f8fc;
  --color-surface-1-oklch__l: 100%;
  --color-surface-1-oklch__c: 0;
  --color-surface-2-oklch__c: 0;
  --color-visited: #36c;
}
#

I adjusted the palette and Citizen uses these variables so everything changed cleanly with just a few lines

mellow lark
#

woah

#

so if you know what variables you're looking for you can just do a bunch of them within one root

#

and change them

hardy helm
#

yup

mellow lark
#

useful to have them all lined up in the common css like a buffet

hardy helm
#

Other skins would require you to go down the rabbit hole and find every single selector and pray you didn't miss one 70_b_dogkek (Cosmos is a special case)

jaunty lake
#

you can make your own variables, it doesn't have to be the same one citizen is using

mellow lark
#

Common is above citizen, is above template specific css

jaunty lake
#

yes there is a load order

mellow lark
#

very interesting

#

learning a lot with this, appreciate your patience

jaunty lake
#

there was a write up, i can't find it anymore. but off the top of my head it is
Common.css
skinspecific.css (like vector.css)
user common.css
user skinspecific.css (myname/vector.css)
inline css

#

so if you want to test things before showing everyone, you go to your personal css pages to preview how it would look to the whole world

mellow lark
#

So to summarise for my and others' future reference:

Question:
How do you change fonts across a wiki using the Citizen skin, with a different font for the body and the headings. These fonts are free fonts imported via url from Google Fonts.

Response:
Common.css should include something like this:

@import url("https://fonts.googleapis.com/css?family=Lora&family=Nunito&display=swap");
:root {
  --font-family-citizen-base: Nunito, sans-serif;
}
.mw-heading, .mw-page-title-main {
    font-family: Lora;
}

Notes

  • In Citizen, you can use root: and variables to change many things about the styling
  • Variables can be defined or just refer to ones in other css files and overwrite them
  • Use the right import url from Google Fonts, for example: https://fonts.googleapis.com/css?family=Lora&family=Nunito&display=swap
    This is the one under Web > Import > Embed code in the head of your html without the weight stuff
  • Use @import url instead of @font-face

Big thanks to @hardy helm, @sour salmon and @jaunty lake for your time and patience. It is very much appreciated

hardy helm
#

(not sure why they put it after user, but anyways)

hardy helm
mellow lark
#

I checked the page n it looked like it did?

#

its nunito

hardy helm
#

It's declared in the CSS, doesn't mean it's actually loading Nunito

#

You probably got it installed locally

mellow lark
#

oh

#

I do yeah

#

Hmm

#

Will be a problem if others use it

#

Does that mean the import link from google fonts is wrong

hardy helm
#

They won't see Nunito, they will see the fallback which in my case is Arial

mellow lark
#

accursed 2009-ass font

#

What would be the correct import link? Or would it just be trial and error

hardy helm
#

Lora and Nunito are variable fonts, and the legacy API can't really handle them (it outputs static fixed-width versions). The newer API (css2) does

mellow lark
#

ahh I see

#

this is freaky, its made mediawiki the body font and common.css the heading font

hardy helm
#

oh i forgot citizen separates those lol

#

Use #firstHeading instead of .mw-page-title-main

mellow lark
#

seems like its fixed it

sour salmon
mellow lark
#

Just in case I come back to this and want to change other heading levels, do you know how i'd find the equivalent of #firstHeading for:

  • big { (so <big></big>)
  • h2{ (so == heading 1 ==)
  • h3{ (so ===heading 2===)
hardy helm
#

(I would discourage using <big>)

mellow lark
#

lmao okay, it was just within a table

#

I will change that

hardy helm
#

But that's a separate conversation 70_b_dogkek

mellow lark
#

haha

hardy helm
#

.mw-heading2, .mw-heading3 { ... }

mellow lark
#

thanks!

#

This was a massive convo, thank you for bearing with me

mellow lark
#

and not having firstHeading produces an error

hardy helm
#

Probably because of the comma

#

Also, <h1-6> use .mw-html-heading

#

If you want Lora for all headings, .mw-heading, .mw-heading-html, #firstHeading { font-family: Lora; }

mellow lark
#

I think if I want to change them in future it might be better to have the levels separately, this seems to work:

#
@import url('https://fonts.googleapis.com/css2?family=Lora:wght@600&family=Nunito:ital@0;1&display=swap');
:root {
  --font-family-citizen-base: Nunito, sans-serif;
}
.mw-html-heading, #h1 {
    font-family: Lora;
}
.mw-html-heading, #h2 {
    font-family: Lora;
}
.mw-html-heading, #h3 {
    font-family: Lora;
}
.mw-html-heading, #h4 {
    font-family: Lora;
}
#

shit, no it doesnt. the caching is my worst enemy

hardy helm
#

Try the CSS I provided

#

Also, #h1 selects the h1 id, not the h1 HTML tag

mellow lark
#

I used .mw-html-heading, and it affects <h1 style></h1> within a column template, but not when I just use <h1></h1> more generally:

#

but does work now

mellow lark
#

I give up. No longer works. the delay makes it impossible to test what works.

#

I'll just wait

spiral venture
#

I would suggest a browser tool like Stylus to test changes before applying them to Common.css

mellow lark
#

Thank you

hardy helm
mellow lark
#

Looks like it is working

mellow lark
#

Not sure how it's supposed to work actually

#

installed the extension but not sure where it shows it applied, on the page you're on?

hardy helm
#

It's on the toolbar

#

Browser toolbar, I mean

mellow lark
#

Oh i can pull up the popup thing but when I put the css in it, I'm not sure what I'm supposed to be looking at

hardy helm
#

That will automatically apply styles to the page

#

it also auto-saves so even if you accidentally close the tab you keep your CSS

#

then after you're done testing you move it to Common.css or wherever

mellow lark
#

oh it shows you if nothing on the page matches whatever you're referring to as well

#

nice

#

trying to find a page with something I can easily identify

hardy helm
#

yup it also higlights them on the page which is handy

#

use devtools to find HTML selectors

mellow lark
#

struggling on twitter

hardy helm
#

X/Twitter and similar platforms usually compile their classes so the HTML isn't particularly readable by humans

mellow lark
#

I'm really sorry for being dense, what colour will selectors be

hardy helm
#

should have a red outline

mellow lark
#

i have mid blue, light blue and orange

hardy helm
#

uhh stylus or the one i linked?

mellow lark
#

the one you linked

#

i'm looking at devtools

#

just trying to find a selector I can test

#

iom selecting text but i dont know how to find the selector for that text

#

like a simple one would be to select some text look in dev tools and find what its called

#

but i can't find it

#

Okay so it will be in the middle bar in elements I think

hardy helm
#

You can find selectors with either devtools or the extension I linked

mellow lark