'Changing font-family for placeholder
Is it posible for an input field to have one font-family
and it's placeholder another?
I have tried to change font-family
for the input's placeholder with an already defined @font-face
in CSS but it's not working:
CSS
.mainLoginInput::-webkit-input-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
.mainLoginInput:-moz-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
HTML
<input class="mainLoginInput" type="text" placeholder="Username" />
How can I solve this problem?
Solution 1:[1]
Found it...
Prefix for Firefox 19+ users is ::-moz-placeholder
And the code looks like this
.mainLoginInput::-moz-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
Solution 2:[2]
In case someone want the placeholders selectors for all browsers :
.mainLoginInput::-webkit-input-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
.mainLoginInput:-ms-input-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
.mainLoginInput:-moz-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
.mainLoginInput::-moz-placeholder {
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
Solution 3:[3]
Use this for major browser support :
HTML:
<input type="text" placeholder="placeholder text.." class="mainLoginInput" />
CSS:
.mainLoginInput::placeholder { /* Chrome, Firefox, Opera, Safari 10.1+ */
font-family: 'myFont', Arial, Helvetica, sans-serif;
opacity: 1; /* Firefox */
}
.mainLoginInput:-ms-input-placeholder { /* Internet Explorer 10-11 */
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
.mainLoginInput::-ms-input-placeholder { /* Microsoft Edge */
font-family: 'myFont', Arial, Helvetica, sans-serif;
}
Details reference link
Solution 4:[4]
Simply like this
.mainLoginInput::placeholder{
font-family: -Your font here-;
}
Solution 5:[5]
Here is the complete use of ::placeholder
pseudo-element:
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: pink;
}
::-moz-placeholder { /* Firefox 19+ */
color: pink;
}
:-ms-input-placeholder { /* IE 10+ */
color: pink;
}
:-moz-placeholder { /* Firefox 18- */
color: pink;
}
All placeholders in Firefox have an opacity value applied to them, so in order to fix this we need to reset that value:
::-moz-placeholder {
opacity: 1;
}
Solution 6:[6]
Simply do this
*{
font-family: --Your font here--
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Goldie |
Solution 2 | |
Solution 3 | |
Solution 4 | FuriousTroller |
Solution 5 | Giacomo Paita |
Solution 6 | coding-spidy |