Search results

Customize the TextBox Background-color and Text-color in Angular TextBox component

15 Oct 2021 / 1 minute to read

You can customize the textbox styles such as background-color, text-color and border-color by overriding its default styles.

To change the styles of the floating label, you must override the style to the input element.

Source
Preview
app.component.ts
app.module.ts
main.ts
index.css
Copied to clipboard
import { Component } from '@angular/core';

@Component({
    selector: 'app-root',
    template: `<div class="wrap">
                <label> Normal Input </label>
                <div class="e-input-group">
                    <input (focus)="focusIn($event.target)" (blur)="focusOut($event.target)" class="e-input" type="text" placeholder="First Name">
                </div>
                 <label> Floating Input </label>
                <div class="e-float-input">
                    <input (focus)="focusIn($event.target)" (blur)="focusOut($event.target)" type="text" required>
                    <span class="e-float-line"></span>
                    <label class="e-float-text">Last Name</label>
                </div>
              </div>`
})

export class AppComponent {
    public focusIn(target: HTMLElement): void {
        target.parentElement.classList.add('e-input-focus');
    }

    public focusOut(target: HTMLElement): void {
        target.parentElement.classList.remove('e-input-focus');
    }
}
Copied to clipboard
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

/**
 * Module
 */
@NgModule({
    imports: [
        BrowserModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }
Copied to clipboard
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';

enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);
Copied to clipboard
#container {
  visibility: hidden;
}

#loader {  
  color: #008cff;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}

.wrap {
  box-sizing: border-box;
  margin: 0 auto;
  padding: 20px 10px;
  width: 260px;
}

.wrap label { /* csslint allow: adjoining-classes */
 font-weight:bold;
}

.wrap .e-float-input {/* csslint allow: adjoining-classes */
   margin:30px 0;
}

.wrap .e-input-group {/* csslint allow: adjoining-classes */
   margin:25px 0;
}


/* To change the background-color and text-color for textbox */ 
.e-input-group,
.e-float-input,
.e-float-input.e-input-group { /* csslint allow: adjoining-classes */
  background : lightgray;
  color: green;
}

/* To change the border-color of the textbox */ 
.e-input-group:not(.e-success):not(.e-warning):not(.e-error):not(.e-float-icon-left),
.e-input-group:hover:not(.e-success):not(.e-warning):not(.e-error):not(.e-float-icon-left) { /* csslint allow: adjoining-classes */
  border-color: #0800ff;
}

/* To change the border-color of the floating-label textbox */ 
.e-float-input input,
.e-float-input:hover:not(.e-input-group):not(.e-success):not(.e-warning):not(.e-error):not(.e-disabled) input:not([disabled]) { /* csslint allow: adjoining-classes */
    border-color: #0800ff;
}