Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font-family is not inherited to the form input fields?

Don't the html form input elements such as input text field or select box automatically inherit the font-family property from the body? For example:

body {  font-family:'Lucida Casual', 'Comic Sans MS'; } 

It will not use the above font in the below form input field:

<form>     <div>         <label for="name">Name</label>           <input id="name" name="name" type="text" />       <div> </form> 

Please have a look at http://jsfiddle.net/3fkNJ/

Is it common that we have to re-define the font family for the input fields, or am i doing something wrong?

like image 678
sunjie Avatar asked Jun 29 '11 12:06

sunjie


People also ask

Does font-family inherit?

If there is a continuous chain of elements (in the sense of parent-child relationships) from the root element to the current element, all with font-family set to inherit or not set at all in any style sheet (which also causes inheritance), then the font is the browser default.

What does inherit font-family mean?

Thanks for asking. The inherit option means it will receive the body's font family. To change to a different font family, you can do that from font manager.

How do you get the font-family in HTML?

There are two types of font family names: family-name - The name of a font-family, like "times", "courier", "arial", etc. generic-family - The name of a generic-family, like "serif", "sans-serif", "cursive", "fantasy", "monospace".


1 Answers

Yes, you need to place the font in the input tag.

input{   padding:5px;   font-size:16px;   font-family:'Lucida Casual', 'Comic Sans MS';     } 

http://jsfiddle.net/jasongennaro/3fkNJ/1/

You can also use inherit to set the font on form fields.

input, textarea, select { font-family:inherit; } 

http://jsfiddle.net/jasongennaro/3fkNJ/7/

EDIT - explanation added

Most browsers render text inside form elements as that of the user's operating system. This is to keep, as I understand it, a common look and feel for the user. However, it can all be overwritten by the code above.

like image 167
Jason Gennaro Avatar answered Sep 20 '22 05:09

Jason Gennaro