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

后端 未结 6 1049
野的像风
野的像风 2020-12-12 23:15

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

6条回答
  •  有刺的猬
    2020-12-12 23:37

    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

提交回复
热议问题