Home > Web Front-end > CSS Tutorial > Why Doesn\'t My \'Input\' Element Inherit the Font from the \'Body\'?

Why Doesn\'t My \'Input\' Element Inherit the Font from the \'Body\'?

Mary-Kate Olsen
Release: 2024-10-28 02:24:30
Original
511 people have browsed it

Why Doesn't My

Input not Inheriting Font from Body

When using CSS to style HTML elements, it can sometimes happen that certain elements do not inherit style properties as expected. This can be the case with input fields, which by default do not inherit the font-family property from their parent element.

In the provided example, the CSS rules are set to define a specific font family for both the body element and custom classes adm applied to both the label and input elements. However, in Firefox, the input field's font does not match that of the label.

To resolve this, you can explicitly specify that the input field should inherit its font from its parent element using CSS:

<code class="css">input, select, textarea, button {
  font-family: inherit;
}</code>
Copy after login

By adding this rule, the input field will now inherit the font-family property defined in the body element, ensuring that it uses the same font as the rest of the text on the page.

You can verify this by viewing a demo: http://jsfiddle.net/gaby/pEedc/1/.

The above is the detailed content of Why Doesn\'t My \'Input\' Element Inherit the Font from the \'Body\'?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template