Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSS font-family

Status
Not open for further replies.

iisman

Technical User
Mar 6, 2005
85
CA
I use the same font-family for all text within a stylesheet, and over an entire site.

can I include this in the body css and will it be inherited throughout all of the other elements?
 
With the exception of bugs: for example, <textarea> does not inherit from <body> in Firefox (I've not checked for other browsers). There also issues with inheritance across <table> tags.

---
Marcus
better questions get better answers - faq581-3339
accessible web design - zioncore.com
 
I think that's how <textarea> is supposed to work - with a monospaced font. Remember that there are attributes that define its size in terms of rows and columns, character width needs to be fixed for that to work. Some other elements have implicit monospace font settings too - <pre>, <code>, <kbd>, <samp>, <tt>. With those exceptions, any font defined for the <body> should be inherited by all elements.

The failure of some old browsers to have font-family inherited by table tags was a bug. I forget which browser(s) had this problem - neither IE5 nor NS4 were great CSS performers (IE was the better of the two in those days - that's how long ago it was!). If you want to bulletproof your pages from having old browsers mess them up in this way (though really that would be the least of your problems with them) you can do this:
Code:
body[red], td, th[/red] {
   font-family: arial, helvetica, sans-serif;
}

body {
   ... other body rules here ...
}
Personally I wouldn't bother.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
iisman,

I set my font in the same style as Chris Hunt with a multi-element selector for the font.

Here's the way I set the font for a page/pages:

body,div,td,h1,p,span,blockquote,textarea {
font-family: verdana,arial,sans-serif;
}

Whatever other elements I use, I stick them in too. I cover every element I plan to use with the particulat font.

For whatever properties are the same in all elements such as font-size and color, I plug that in too.

Then use separate class or id selectors with declarations for the individual elements that have different properties for the colors, font-size, etc.





Youth and beauty are no match for age and experience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top