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

Css

Css Problem Overview


When I set the font family, font size, color etc. it seems that some nested elements override these with ugly browser defaults.

Must I really specify those a dozens of times for any kind of element on my page, or is there a way to set them globally once and forever?

How to do that?

Css Solutions


Solution 1 - Css

* {
 font-size: 100%;
 font-family: Arial;
}

The asterisk implies all elements.

Solution 2 - Css

If you're using IE, chances are it will revert to the browser defaults for certain elements, like tables. You can counter that with something like 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 may want to read up on CSS resets; see threads like this one

Solution 3 - Css

I can't stress this advice enough: use a reset stylesheet, then set everything explicitly. It'll cut your cross-browser CSS development time in half.

Try Eric Meyer's reset.css.

Solution 4 - Css

you can set them in the body tag

body
{
    font-size:xxx;
    font-family:yyyy;
}

Solution 5 - Css

If you specify CSS attributes for your body element it should apply to anything within <body></body> so long as you don't override them later in the stylesheet.

Solution 6 - Css

If you want to set styles of all elements in body you should use next code^

  body{
    color: green;
    }

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionProud MemberView Question on Stackoverflow
Solution 1 - CssBazzzView Answer on Stackoverflow
Solution 2 - CssPaulView Answer on Stackoverflow
Solution 3 - CssChris CoxView Answer on Stackoverflow
Solution 4 - CssjimplodeView Answer on Stackoverflow
Solution 5 - CssTyler TreatView Answer on Stackoverflow
Solution 6 - CssStepan PoperechnyiView Answer on Stackoverflow