Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background color in outline input field

I want to change the background color of my searchbar. It has the appearance="outline" and I like the design, but if I set a new color it goes over the borders and looks ugly. What can I do here?

My CSS:

::ng-deep .mat-form-field-appearance-outline .mat-form-field-infix {
  padding: 5%;
}

::ng-deep .mat-form-field-infix {
  top: -3px;
}

::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
  background-color: white;
}

My HTML:

<mat-form-field style="width:110%;" appearance="outline" >
    <mat-icon matPrefix>search</mat-icon>
    <input type="search" name="test" [(ngModel)]="searchText"
    placeholder="Search" aria-label="Search" matInput>
</mat-form-field>

Enter image description here

like image 978
CptDayDreamer Avatar asked Apr 11 '19 16:04

CptDayDreamer


People also ask

How do I change the background color of a text field in HTML?

To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.

How do you change the input field color in HTML?

The <input type="color"> defines a color picker. The default value is #000000 (black). The value must be in seven-character hexadecimal notation. Tip: Always add the <label> tag for best accessibility practices!

How do I change the background color of a text box in CSS?

To add background color to the form input, use the background-color property.


1 Answers

You can add border-radius to the div where you are changing the background.

I have tested border-radius: 5px and it looks good.

Code for you

I am assuming this background CSS is working for you. I just tried this with your selector.

::ng-deep .mat-form-field-appearance-outline .mat-form-field-outline {
  background-color: white;
  border-radius: 5px;
}

Screenshot: http://prntscr.com/nanu75

like image 128
Johar Zaman Avatar answered Sep 21 '22 09:09

Johar Zaman