Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this the right way to set font family for all headings and everything inside the headings?

Tags:

css

I want all headings and everything in them, such as anchor tags, to be a certain font family. This works:

h1, h2, h3, h4, h5, h6, h1 > *, h2 > *, h3 > *, h4 > *, h5 > *, h6 > * {
 font-family: serif;
}

I was wondering if this is the most efficient way to do it?

like image 691
Scot's Scripts Avatar asked Sep 12 '25 06:09

Scot's Scripts


2 Answers

font-family is inherited, so it you're not overriding it elsewhere, you can simply do this which will work for the child elements too:

h1, h2, h3, h4, h5, h6 {font-family:serif;}

If you are overriding it elsewhere, then it depends how exactly you're overriding it to know what specificity you need here.

like image 135
andi Avatar answered Sep 14 '25 19:09

andi


If you would like to apply it to all texts (paragraph or headers), you could use

* {font-family: sans-serif} in your CSS file

like image 22
Saron Gebre Avatar answered Sep 14 '25 21:09

Saron Gebre