Home >Web Front-end >CSS Tutorial >Why do fields not inherit font styles from their parent elements in all browsers?
fields not inherit font styles from their parent elements in all browsers? " />
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!