How to specify font attributes for all elements on an html web page?

When I set the font family, font size, color, etc., it seems like some nested elements override them with ugly browser settings.

Do I really have to specify these dozens of times for any element on my page, or is there a way to set them globally once and for all?

How to do it?

+82
css
Oct. 15 '10 at 12:35
source share
5 answers
* { font-size: 100%; font-family: Arial; } 

An asterisk means all elements.

+157
Oct. 15 2018-10-15
source share

If you use IE, most likely it will revert to the browser defaults for certain elements, such as tables. You can come across this with the following CSS:

 html, body, form, fieldset, table, tr, td, img { margin: 0; padding: 0; font: 100%/150% calibri,helvetica,sans-serif; } input, button, select, textarea, optgroup, option { font-family: inherit; font-size: inherit; font-style: inherit; font-weight: inherit; } /* rest of your styles; like: */ body { font-size: 0.875em; } 

Edit: you can read about CSS dumps; see topics like this

+15
Oct. 15 2018-10-15
source share

I cannot emphasize this advice enough: use the reset stylesheet, and then set everything explicitly. This will cut the cross browser development time by half.

Try Eric Meyer reset.css.

+9
Oct. 15 '10 at 19:07
source share

you can set them in body tag

 body { font-size:xxx; font-family:yyyy; } 
+7
Oct 15 '10 at 12:37
source share

If you specify CSS attributes for your body element, it should apply to everything within <body></body> unless you redefine them later in the stylesheet.

+1
Oct. 15 '10 at 12:37
source share



All Articles