Home  >  Article  >  Web Front-end  >  Why do fields not inherit font styles from their parent elements in all browsers?

Why do fields not inherit font styles from their parent elements in all browsers?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-27 06:31:29949browse

Why do <input> fields not inherit font styles from their parent elements in all browsers? 
fields not inherit font styles from their parent elements in all browsers? " />

Font Inheritance Issue in Fields

In an HTML document, certain elements may not inherit the font style defined for their parent element. This can be observed for fields, as illustrated in a specific example:

<label class="adm" for="UserName">User name</label><br><input class="adm" id="UserName" name="UserName" size="30" type="text" value="" />

If CSS is applied to inherit the font family from the element to these form elements:

body,html { font-family: Verdana,Arial,Helvetica,sans-serif; margin:0; padding:0; color: #111;}<br>label.adm  { font-size:0.9em; margin:0 0 3px 3px; display: block;}<br>input.adm  { font-size:0.9em; margin:0 0 3px 3px; }

Firefox renders these elements with different fonts. While the

This discrepancy arises because the element does not inherit the font family by default in all browsers. To explicitly force inheritance, CSS can be used:

input, select, textarea, button{font-family:inherit;}<br>

By incorporating this rule, the field will inherit the font family from its parent element, ensuring consistency in font style. A live demonstration of this solution can be found at http://jsfiddle.net/gaby/pEedc/1/.

The above is the detailed content of Why do fields not inherit font styles from their parent elements in all browsers?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn