fail to change placeholder color with Bootstrap 3

前端 未结 10 827
暗喜
暗喜 2021-01-31 01:27

Two questions:

  1. I am trying to make the placeholder text white. But it doesn\'t work. I am using Bootstrap 3. JSFiddle demo

  2. Another question is h

相关标签:
10条回答
  • 2021-01-31 01:36

    A Possible Gotcha

    Recommended Sanity Check - Make sure to add the form-control class to your inputs.

    If you have bootstrap css loaded on your page, but your inputs don't have the
    class="form-control" then placeholder CSS selector won't apply to them.

    Example markup from the docs:

    I know this didn't apply to the OP's markup but as I missed this at first and spent a little bit of effort trying to debug it, I'm posting this answer to help others.

    0 讨论(0)
  • 2021-01-31 01:36

    You should check out this answer : Change an HTML5 input's placeholder color with CSS

    Work on most browser, the solution in this thread is not working on FF 30+ for example

    0 讨论(0)
  • 2021-01-31 01:38

    I think qwertzman is on the right track for the best solution to this.

    If you only wanted to style a specific placeholder, then his answer still holds true.

    But if you want to override the colour of all placeholders, (which is more probable) and if you are already compiling your own custom Bootstrap LESS, the answer is even simpler!

    Override this LESS variable: @input-color-placeholder

    0 讨论(0)
  • 2021-01-31 01:49

    The others did not work in my case (Bootstrap 4). Here is the solution I used.

    html .form-control::-webkit-input-placeholder { color:white; }
    html .form-control:-moz-placeholder { color:white; }
    html .form-control::-moz-placeholder { color:white; }
    html .form-control:-ms-input-placeholder { color:white; }
    

    If we use a stronger selector (html first), we don't need to use the hacky value !important.

    This overrides bootstraps CSS as we use a higher level of specificity to target .form-control elements (html first instead of .form-control first).

    0 讨论(0)
  • 2021-01-31 01:54

    I'm using Bootstrap 4 and Dennis Puzak's solution does not work for me.

    The next solution works for me

    .form-control::placeholder { color: white;} /* Chrome, Firefox, Opera*/
    :-ms-input-placeholder.form-control { color: white; }  /* Internet Explorer*/
    .form-control::-ms-input-placeholder { color: white; }  /* Microsoft Edge*/
    
    0 讨论(0)
  • 2021-01-31 01:55

    Boostrap Placeholder Mixin:

    @mixin placeholder($color: $input-color-placeholder) {
      // Firefox
      &::-moz-placeholder {
        color: $color;
        opacity: 1; // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526
      }
      &:-ms-input-placeholder { color: $color; } // Internet Explorer 10+
      &::-webkit-input-placeholder  { color: $color; } // Safari and Chrome
    }
    

    now call it:

    @include placeholder($white);
    
    0 讨论(0)
提交回复
热议问题