Changing border color in mat-form-field

前端 未结 8 1477
猫巷女王i
猫巷女王i 2020-12-14 22:59

I am using angular material mat-form-field. I have a dark background, and therefore am trying to change the border of the form-field to white. But I am not able

相关标签:
8条回答
  • 2020-12-14 23:18

    I think this will cover everything.

    // mat-icon-stepper selected color change 
    ::ng-deep .mat-step-header .mat-step-icon-selected, .mat-step-header .mat-step-icon-state-done, .mat-step-header .mat-step-icon-state-edit {
        background-color: red!important;
    }
    
    //input outline color
    ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
        color: red!important;
        // opacity: 1!important;
    }
    
    //mat-input focused color
    ::ng-deep .mat-form-field-appearance-outline.mat-focused .mat-form-field-outline-thick {
        color: red!important;
    }
    
    // mat-input error outline color
    ::ng-deep .mat-form-field-appearance-outline.mat-form-field-invalid.mat-form-field-invalid .mat-form-field-outline-thick{
        color: red!important;
        opacity: 0.8!important;
    }
    
    // mat-input carent color
    ::ng-deep .mat-input-element {
        caret-color: red!important;
    }
    
    // mat-input error carent color
    ::ng-deep .mat-form-field-invalid .mat-input-element, .mat-warn .mat-input-element {
        caret-color: red!important;
    }
    
    // mat-label normal state style
    ::ng-deep .mat-form-field-label {
        color: rgba(0,0,0,.6)!important;
        // color: $mainColor!important;
    }
    
    // mat-label focused style
    ::ng-deep .mat-form-field.mat-focused .mat-form-field-label {
        color: red!important;
    }
    
    // mat-label error style
    ::ng-deep .mat-form-field.mat-form-field-invalid .mat-form-field-label {
        color: red!important;
    }
    
    0 讨论(0)
  • 2020-12-14 23:28

    SCSS version of @sasa with colors as variables

    ::ng-deep {
       $custom-main-color: red;
       $custom-label-color: rgba(0, 0, 0, .6);
    
       // mat-icon-stepper selected color change
       .mat-step-header .mat-step-icon-selected, .mat-step-header .mat-step-icon-state-done, .mat-step-header .mat-step-icon-state-edit {
          background-color: $custom-main-color !important;
       }
    
       // input outline color
       .mat-form-field-appearance-outline .mat-form-field-outline {
          color: $custom-main-color !important;
       }
    
       // mat-input focused color
       .mat-form-field-appearance-outline.mat-focused .mat-form-field-outline-thick {
          color: $custom-main-color !important;
       }
    
       // mat-input error outline color
       .mat-form-field-appearance-outline.mat-form-field-invalid.mat-form-field-invalid .mat-form-field-outline-thick {
          color: $custom-main-color !important;
          opacity: 0.8 !important;
       }
    
       // mat-input caret color
       .mat-input-element {
          caret-color: $custom-main-color !important;
       }
    
       // mat-input error caret color
       .mat-form-field-invalid .mat-input-element, .mat-warn .mat-input-element {
          caret-color: $custom-main-color !important;
       }
    
       // mat-label normal state style
       .mat-form-field-label {
          color: $custom-label-color !important;
       }
    
       // mat-label focused style
       .mat-form-field.mat-focused .mat-form-field-label {
          color: $custom-main-color !important;
       }
    
       // mat-label error style
       .mat-form-field.mat-form-field-invalid .mat-form-field-label {
          color: $custom-main-color !important;
       }
    }
    
    0 讨论(0)
  • 2020-12-14 23:32

    Add this CSS to your form-field-appearance-example.css:

    /* Border */
    .mat-form-field-appearance-outline .mat-form-field-outline {
      color: white;
    }
    /* Font color */
    input.mat-input-element {
      color: white;
    }
    

    Though, there is still a problem while the field is focused.

    0 讨论(0)
  • 2020-12-14 23:36

    I had tried many things, finally, I am able to change the bottom line (which we are thinking is a border, which is actually not a border), using this:

    ::ng-deep.mat-form-field.mat-focused .mat-form-field-ripple{
        background-color: black;
    }
    

    That colored line is actually span filled with color! Hope this helps :)

    0 讨论(0)
  • 2020-12-14 23:38

    try this , add/remove ::ng-deep if required

     ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline-end {
                    border-radius: 1px !important;
                    border: 1px solid  red;
                    border-left:none;
                  }
                ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline-start {
                    border-radius: 1px !important;
                    border: 1px solid red;
                    border-right:none;
                  }
                  ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline-gap {
                    border-radius: 1px !important;
                    border-bottom: 1px solid   red;
                  }
    
    0 讨论(0)
  • 2020-12-14 23:40

    remove boder and add box-shadow :

    ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline-end {
            border-radius: 50% !important;
            border: none;
            border-left: none;
        }
        ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline-start {
            border-radius: 1px !important;
            border: none;
            border-right: none;
        }
        ::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline-gap {
            border-radius: 1px !important;
            border-bottom: none;
        }
        
        ::ng-deep.mat-form-field-appearance-outline .mat-form-field-outline {
            box-shadow: -5px -5px 20px #fff, 5px 5px 20px #babecc;
            border-radius: 15px;
        }
    
    0 讨论(0)
提交回复
热议问题