Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

::-webkit-input-placeholder does not work [duplicate]

i'm writing a mobile web sites and i'm styling it with sass.

I would like to change the placeholder color of textinput, but i'm not able to do this.

This is the mixin for the placeholder

@mixin placeholder($color) {
  ::-webkit-input-placeholder {color: $color}
  :-moz-placeholder           {color: $color}
  ::-moz-placeholder          {color: $color}
  :-ms-input-placeholder      {color: $color}
}

And then i use it included into a class

.input-class {
    @include placeholder(#FFFFFF);
}

Finally set the class to the input

<input class="input-class" ...>

But nothing happens. In addition my IDE set an error on the mixins lines saying me: "Unknown pseudo selector -webkit-input-placeholder" and chrome seems to not recognize that tag.

How can I change the color of placeholder? No matter if the response is in sass or css.

Thanks in advance.

like image 513
guest9119 Avatar asked Jan 15 '15 09:01

guest9119


People also ask

What is Webkit input placeholder?

CSS - ::-webkit-input-placeholder The non-standard proprietary ::-webkit-input-placeholder pseudo-element represents the placeholder text of a form element. This allows web developers and theme designers to customize the appearance of placeholder text. This pseudo-class is only supported by WebKit and Blink.

How do I override placeholder in CSS?

Step 2) Add CSS: 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.

How do I inspect placeholder in Chrome CSS?

For Google Chrome Version 69: Open Inspect Elements: On Mac ⌘ + Shift + C, on Windows / Linux Ctrl + Shift + C OR F12.

How do I change placeholder text in CSS?

Use the ::placeholder pseudo-element to style your placeholder text in an <input> or <textarea> form element. Most modern browsers support this, but for older browsers, vendor prefixes will be required.


1 Answers

You can't use it single, only with selector:

input::-webkit-input-placeholder {
    color: #9B9B9B;
}

input:-ms-input-placeholder {
    color: #9B9B9B;
}

input::-moz-placeholder {
    color: #9B9B9B;
}

Mixin:

@mixin placeholder($selector, $color) {
  #{$selector}::-webkit-input-placeholder {color: $color}
  #{$selector}::-moz-placeholder          {color: $color}
  #{$selector}:-ms-input-placeholder      {color: $color}
}

Usage:

@include placeholder('.input-class', #FFFFFF);

Live example

P.S. Do not use them all together (this selector is broken and css parser will always fails):

input::-webkit-input-placeholder,//Not WebKit will fails here
input:-ms-input-placeholder,//Not IE will fails here
input::-moz-placeholder {//Not Firefox will fails here
    color: #9B9B9B;
}
like image 85
Pinal Avatar answered Sep 22 '22 08:09

Pinal