Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Cannot change placeholder color by class

Tags:

html

css

I'm working with a project where the placeholder color was defined globally by developer. But now I need to style a form with a different placeholder color. How can I address it correctly?

js fiddle

CSS

::-webkit-input-placeholder {
color: red;
}
:-moz-placeholder {
color: red;

}
::-moz-placeholder {
color: red;

}
:-ms-input-placeholder {
color: red;

}


.box input::-webkit-input-placeholder, .box textarea::-webkit-input-placeholder {
  color: blue;
}
.box input:-moz-placeholder, .box textarea:-moz-placeholder {
  color: blue;
}
.box input:-ms-input-placeholder, .box textarea:-ms-input-placeholder{
  color: blue;
}
like image 293
user2952265 Avatar asked Jan 14 '14 11:01

user2952265


People also ask

How do I change the color of a placeholder?

In most browsers, the placeholder text is grey. To change this, style the placeholder with the non-standard ::placeholder selector. Note that Firefox adds a lower opacity to the placeholder, so we use opacity: 1 to fix this.

What is placeholder default color?

Note: In most browsers, the appearance of placeholder text is a translucent or light gray color by default.

How do I change placeholder text in CSS?

Change Input Placeholder Text with CSS You can use the ::placeholder pseudo-element to change the styles of the placeholder text, which includes the ability to change the background. The code in this example uses a Sass function to generate code for support in older browsers as well.

What is placeholder color CSS?

CSS ::placeholder Selector The placeholder text is set with the placeholder attribute, which specifies a hint that describes the expected value of an input field. Tip: The default color of the placeholder text is light grey in most browsers.


1 Answers

Try this code:

http://jsfiddle.net/vyDns/3/

you where close only needed to add .box in front like:

 .box::-moz-placeholder

Cheers

like image 176
Filip Huysmans Avatar answered Oct 02 '22 18:10

Filip Huysmans