I am trying to use font shorthand in my h1 tag. However, it’s not working when I don’t specify the font size in the shorthand. I want to use the same font as the h1 tag in my .title class.
This is my current HTML code:
<div class="landing">
<h1 class="title">
Hello there
</h1>
</div>
And this is my current CSS code:
h1 {
font-size: var(--font-size-lg);
}
.landing .title {
font: bold var(--main-font), var(--fall-back-font);
line-height: calc(var(--line-height)*2);
letter-spacing: -1px;
}
I have tried setting the font shorthand property in my .title
class to use the same font as the h1 tag, but it doesn’t work unless I also specify the font size in the shorthand.
I want to be able to use the same font without having to specify the font size again.
2
Answers
to achieve, there are ‘css selectors’ :
just add the selector of your choice with the div css part.
update :
shorthand need a value, you have to initialise the value before recall it
then in your css statements :
The specification (see also MDN) for the
font
property requires that you specify thefont-family
and thefont-size
. (The other properties it is a shorthand for are optional.) You can’t use it without specifying the font size as to do so would be a syntax error.If you just want to set the
font-family
then use thefont-family
property instead of thefont
shorthand property.