Jennie Zong
Jennie Zong

Reputation: 11

Can I use font:monospace?

It seems it doesn't work if I use font:monospace. But It's worked for font-family:monospace. What's the difference beteew font and font-family?

Upvotes: 1

Views: 174

Answers (2)

PSL
PSL

Reputation: 123739

You need to atleast specify font-size while specifying the shorthand property for font along with the family. Otherwise everything will have its own initial values.

See the definition below.

[ [ <‘font-style’> || || <‘font-weight’> || <‘font-stretch’> ]? <‘font-size’> [ / <‘line-height’> ]? <‘font-family’> ] | caption | icon | menu | message-box | small-caption | status-bar

An example:

selector{
   font:12px monospace;
}

When specifying shorthand property using font font-size must precede font-family and both are mandatory (the ones in angle brackets and not in square brackets) atleast.

Upvotes: 3

Steve Bergamini
Steve Bergamini

Reputation: 14600

Font is the shorthand looking for several properties. Example:

p
{
font:15px arial,sans-serif;
}

While font-family is just looking for the actual font. Example:

p
{
font-family:"Times New Roman",Georgia,Serif;
}

Upvotes: 0

Related Questions