Different fonts for different placeholder values - html

I know how to change the font-family of input and textarea in html. But what I am concerned with is - is it possible for two textarea fields to have fonts different from each other? If yes, then how?
Thanks.

You can style your textarea placeholders differently using a combination selector:
#two:-prefix-input-placeholder
For example will style the placeholder with the id 'two' whilst including the placeholder prefix. See below for an example of this (tested on chrome and IE 11):
::-webkit-input-placeholder {
color: red;
}
:-moz-placeholder { /* Firefox 18- */
color: red;
}
::-moz-placeholder { /* Firefox 19+ */
color: red;
}
:-ms-input-placeholder {
color: red;
}
/***********************/
#two::-webkit-input-placeholder {
color: blue;
}
#two:-moz-placeholder { /* Firefox 18- */
color: blue;
}
#two::-moz-placeholder { /* Firefox 19+ */
color: blue;
}
#two:-ms-input-placeholder {
color: blue;
}
<textarea placeholder="this is some text"></textarea>
<textarea placeholder="this is some text" id="two"></textarea>

You should set two different CSS classes on the textareas. Then you can choose separate fonts for each class in your CSS.

Give your textareas an id
<textarea rows="4" cols="50" placeholder="Some text" id="txtFont1"></textarea>
<textarea rows="4" cols="50" placeholder="Some text" id="txtFont2"></textarea>
Then style them
#txtFont1{
font-family: century gothic;
}
#txtFont2{
font-family: times new roman;
}

You can use different selectors for each input and then target them to apply different fonts in them.
However, be aware that using additional fonts adds loading time to site pages so you should be careful and balance styling and performance.

Related

Where to find input placeholder style

Couldn't find default placeholder style for input element.
There are no any webkit-input-placeholder, -moz-placeholder, -moz-placeholder, or -ms-input-placeholder style settings in any css files.
UPDATE: Guys, don't hurry to judge me.
I have the legacy code (tones of css files). The one placeholder style (font-weight, color and so on) is not properly shown in IE 11. I started to find where the placeholder style is defined. And I didn't find any placeholder style declaration you all mentioned.
So I assume there is a default style for placeholder in browser.
Webkit's User Agent Stylesheet (Chrome & Safari) can be found here: http://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css
Their CSS shows:
::placeholder {
-webkit-text-security: none;
color: darkGray;
pointer-events: none !important;
}
input::placeholder, isindex::placeholder {
white-space: pre;
word-wrap: normal;
overflow: hidden;
}
I can't find any other sources that have the defaults for other browsers, but I imagine they would be close to this.
Please do refer the style for PlaceHolder...
<input placeholder='hello'/> <br />
<textarea placeholder='hello'></textarea>
For Example
/* do not group these rules */
*::-webkit-input-placeholder {
color: red;
}
*:-moz-placeholder {
/* FF 4-18 */
color: red;
}
*::-moz-placeholder {
/* FF 19+ */
color: red;
}
*:-ms-input-placeholder {
/* IE 10+ */
color: red;
}
To style the place holders you should use vendor-prefixed selectors
::-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;
}
You can even scope the elements,
input[type="email"].user_email::-webkit-input-placeholder {
color: blue;
}
Please refer this answer, Different place holder implementations and usage
Placeholder styling supported by a lot of browsers,
look here: http://caniuse.com/#feat=input-placeholder
Example -
Style:
<style type="text/css">
input:-ms-input-placeholder {
color:pink;
font-style:italic;
text-transform:uppercase;
text-align:center;
}
input::-webkit-input-placeholder {
color:pink;
font-style:italic;
text-transform:uppercase;
text-align:center;
}
input:-moz-placeholder {
color:pink;
font-style:italic;
text-transform:uppercase;
text-align:center;
}
/* firefox 19+ */
input::-moz-placeholder {
color:pink;
font-style:italic;
text-transform:uppercase;
text-align:center;
}
</style>
HTML:
<input type="text" placeholder="Placeholder Text" size="40">
working code on Plunker: https://plnkr.co/edit/bpTg4zIQfGD580XKo7q8?p=preview

How to change placeholder color of specific input field?

I want to change the color of specific place holder. I'm using many input fields for my project, problem is that in some section i need grey color for placeholder and in some section i need white color for placeholder. I have searched for this purpose and find this solution.
::-webkit-input-placeholder { /* WebKit, Blink, Edge */
color: #909;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: #909;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: #909;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10-11 */
color: #909;
}
But this code is implement on all input placeholder, and i don't need all input placeholder in same color. So can anyone please help me. Thanks in advance.
You need to assign the -input-placeholder to some classname and add that class to any input you need its placeholder to have this, just like this JS Fiddle
.change::-webkit-input-placeholder {
/* WebKit, Blink, Edge */
color: #909;
}
.change:-moz-placeholder {
/* Mozilla Firefox 4 to 18 */
color: #909;
opacity: 1;
}
.change::-moz-placeholder {
/* Mozilla Firefox 19+ */
color: #909;
opacity: 1;
}
.change:-ms-input-placeholder {
/* Internet Explorer 10-11 */
color: #909;
}
input[type="text"]{
display:block;
width:300px;
padding:5px;
margin-bottom:5px;
font-size:1.5em;
}
<input type="text" placeholder="text1" class="change">
<input type="text" placeholder="text2">
<input type="text" placeholder="text3">
<input type="text" placeholder="text4" class="change">
<input type="text" placeholder="text5">
You could also use a Javascript solution without placeholder to do what you want to do. Here is the code:
//This fix allows you to change the color to whatever textcolor is while also making text go away when you click on it. However, this fix does not put the temporary placeholder back into the textarea when there is no text inside the input.
<input type="text" id="usr" value="Username" onclick="this.value = '';" style="color: red;"/>
<input type="text" id="pwd" value="Password" onclick="this.value = ''; this.type = 'password';" style="color: green;"/>
Please not that this fix is a temporary placeholder and should not be used for actual login forms. I would suggest using what #Ayaz_Shah recommended in his answer.
input::-moz-placeholder {
color: white;
}
input:-moz-placeholder {
color: white;
font-size: 14px !important;
}
*::-webkit-input-placeholder {
color: white;
font-size: 14px !important;
}
*:-ms-input-placeholder {
color: white;
font-size: 14px !important;
}
*:-moz-placeholder {
color: white;
font-size: 14px !important;
}

how to change the color of the placeholder of the input in html [duplicate]

This question already has answers here:
Change a HTML5 input's placeholder color with CSS
(43 answers)
Closed 8 years ago.
I would like to change the color of the placeholder of my textfield. Here is my code. Thanks in advance
<input type="text" placeholder="input here"/>
Here is jsFiddle for you. Solution
You can use following css to implement the same
::-webkit-input-placeholder { /* WebKit browsers */
color: #909;
}
:-moz-placeholder {
color: #999;
}
::-moz-placeholder {
color: #999;
}
:-ms-input-placeholder {
color: #999;
}
You can use style to change the color of placeholder.
<input type="text" placeholder="input here" />
Then in your css write-
::-webkit-input-placeholder { /* WebKit browsers */
color: Red;
}
:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
color: Red;
opacity: 1;
}
::-moz-placeholder { /* Mozilla Firefox 19+ */
color: Red;
opacity: 1;
}
:-ms-input-placeholder { /* Internet Explorer 10+ */
color: Red;
}
See the output in http://jsfiddle.net/w1wjo6q4/1/
Thanks & Regards

how to format input placeholder text for the Opera browser?

I have styled placeholder text with CSS using the psuedo elements and pseudo classes below. This gets the job done on all major browsers but Opera. My understanding is Opera does not support styling placeholder text. Does anyone know of a way to style Opera input placeholder text?
CSS
::-webkit-input-placeholder {
color: red;
font-size: 10px;
}
::-moz-placeholder {
color: red;
font-size: 10px;
}
:-moz-placeholder {
color: red;
font-size: 10px;
}
:-ms-input-placeholder {
color: red;
font-size: 10px;
}
input:-moz-placeholder {
color: red;
font-size: 10px;
}
Both existing ways to style placeholder available in Firefox and WebKit are vendor-prefixed and nonstandard and should not be used in production. For future-proofness, use JavaScript to remove placeholder attribute and use either value (in conjunction with a class like placeholder to bind placeholder styles to) of form field or an additional text element to emulate placeholder functionality. This will work consistently across browsers (current and future ones) including Opera.
Opera supports placeholder text styling starting from version 22.0.1471.70 (17 June, 2014), so above CSS works now.
You can style the placeholders like so:
::-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;
}
I would suggest to check this link to check for browser compatibility: https://caniuse.com/#search=input-placeholder

change font colour in textbox with CSS when value is typed into box

I have a text box, which acts as a search box on my page. I pre-populate the field with the word 'SEARCH' which has a default text colour of #D6D6D0.
Using CSS, is it possible to change the text colour to #FFFFFF when someone enters text in the box?
<input type="text" name="q" value="SEARCH" id="searchFieldText">
#searchFieldText {
background: url("/images/crmpicco/search_bg3.png") no-repeat scroll 0 0 #000000;
border: medium none;
color: #D6D6D0;
float: left;
font-family: Arial,Helvetica,sans-serif;
font-size: 10px;
height: 21px;
padding-left: 0;
padding-top: 3px;
width: 168px;
}
The focus pseudo class should work
#searchFieldText:focus {
color: #fff;
}
Using :focus will only apply when the box is currently in focus, when the user comes out of the text box the color will revert.
I would suggest using the placeholder attribute, override the styling for the placeholder to be the #D6D6D0 color you wanted and apply the style you want on the textbox.
You can override the placeholder styling with these psuedo selectors:
::-webkit-input-placeholder {
color: #D6D6D0;
}
:-moz-placeholder {
color: #D6D6D0;
}
::-moz-placeholder {
color: #D6D6D0;
}
:-ms-input-placeholder {
color: #D6D6D0;
}
I made a fiddle that gives you an idea: http://jsfiddle.net/bM5AE/
You can better use placeholder to pre-populate fields, on typing they will be gone, if onblur the field is empty the placeholder comes back.
<input type="text" name="q" placeholder="SEARCH" id="searchFieldText">
And if you wan't to style the placeholder
::-webkit-input-placeholder {
color: red;
}
:-moz-placeholder { /* Firefox 18- */
color: red;
}
::-moz-placeholder { /* Firefox 19+ */
color: red;
}
:-ms-input-placeholder {
color: red;
}
Example
Using the pseudoclass :focus will do the trick for you.
#searchFieldText:focus{
color:#fff;
}
I also recommend you to use the new attribute placeholder for the input field which will do some magic for you (need to be aware of support however).
See the example
hi Try the below code it will work....
$(document).ready(function () {
$("#searchFieldText").keypress(function () {
$("#searchFieldText").css("color", "#ffffff");
});
});