How do I change md-input-container placeholder color using css in angular material?
Placeholder is depicted as a <label>
in Angular Material. So you actually need to style the label not the placeholder.
As soon as you click (focus) on the input this <label>
which is looking as a placeholder slides up and converted into a form <label>
.
So you just need to apply this CSS:
/* When the input is not focused */
md-input-container label {
color: red;
}
/* When the input is focused */
md-input-container.md-input-focused label {
color: blue;
}
Have a look at this Plunkr Demo.
angular 4 md input container
All you need to do is just replacing html codes with angular material components. Angular material components have support for form controls. For example;
<div [formGroup]="form">
<div [ngSwitch]="question.controlType">
// You can use components by wrapping with `ng-template`
<ng-template *ngSwitchCase="'textbox'">
<md-input-container>
<input mdInput placeholder="{{question.label}}" [formControl]="yourFormControlName">
</md-input-container>
</ng-template>
// Or like this
<md-checkbox *ngSwitchCase="'checkbox'">
{{question.label}}
</md-checkbox>
//...
</div>
</div>
This section has lots of examples about usage, you can combine them with dynamic forms easily.
Angular Material 2 md-input-container not working
import { MdInputModule } from '@angular/material';
And add MdInputModule
in imports: [ MdInputModule ]
in @NgModule
in app.ts
Change angular material input style
This is the CSS selector used by Angular Material:
md-input-container:not(.md-input-invalid).md-input-focused .md-input {
border-color: your_color_here;
}
For what controls should I use md-input-container
md-input-container
has to be a parent container for any type of input (text, number, date, etc) in order to get that material look and feel.
However, if you do not need these material-styled placeholders, labels and validation, you can still use input which is not nested in the container. That was the case in the Sliders example.
Related Topics
Bootstrap 4: How to Have a Full Width Navbar with The Content in a Container (Like The So Navbar)
How to Apply CSS to a MAC Chrome Select Box
Webpack 4: Mini-CSS-Extract-Plugin + Sass-Loader + Splitchunks
How to Set The Background-Position to an Absolute Distance, Starting from Right
How to Force Twitter Bootstrap .Dl-Horizontal Dt Content to Wrap Instead of Truncate
How to Convert Whole Folder with Convert-Sass? (Scss to Sass)
Gulp SASS - How to Properly Name The Output CSS
CSS Stylesheets at Top or Bottom? or How to Solve Blank Page Issue
Vertical Alignment Based on X-Height
CSS Bootstrap Overrides My Own CSS
Selected Text Background Color
Bootstrap 5 Form-Group, Form-Row, Form-Inline Not Working
Float a Div in Top Right Corner Without Overlapping Sibling Header
Class Names Concatenated or Separated by a Space
Make Div Max-Height Equal to 'Window Height - 100Px'