Customizing the Style of Mat-Form-Field

I have designed a search bar using mat-form-field and attempted to personalize the appearance. Currently, there is a gray border-like region surrounding the input field and icons. Moreover, clicking on the input field results in a visible border:

<form #formRef="ngForm" class="form-inline" (ngSubmit)="searchTicker(searchInput.value)" #form="ngForm" [formGroup]="formGroup" style="display:flex; justify-content: center; ">
    <mat-form-field style="width: 400px;" class="search-bar">
        <div style="display: flex; align-items:center;" class="search-bar-container">
            <input #searchInput class="form-control" placeholder="Enter Stock Ticker Symbol" 
            matInput [matAutocomplete]="auto" formControlName = "tickerValue" value="selectedTicker" style="background-color:white;">
            <mat-autocomplete #auto="matAutocomplete">
                <mat-option *ngFor="let item of ACArray" [value]="item.symbol" (click)="selectOption(item.symbol)"> {{item.symbol}} | {{item.description}} </mat-option>
            </mat-autocomplete>
            <button mat-icon-button type="submit"> 
                <mat-icon>search</mat-icon>
            </button>
            
            <button mat-icon-button (click)="searchInput.value='' ; clearResults()"> 
                <mat-icon>close</mat-icon>
            </button>
        </div>
    </mat-form-field>
</form>
.search-bar-container{
    background: white;
}

Is there a way to eliminate this gray area (or make it white) and get rid of the border around the input field?

I have experimented with various solutions recommended on this platform but none proved successful.

Your assistance would be greatly appreciated!

Answer №1

Make sure to include this customized CSS code in your global styles.scss or specific component CSS file:

/* Get rid of the gray border and background */
.mat-form-field {
  border: none;
  background-color: transparent;
}

/* Remove focus outline */
.mat-form-field.mat-focused .mat-form-field-underline {
  display: none;
}

/* Eliminate border and background on input element */
.mat-form-field-wrapper {
  background-color: transparent;
  border-radius: 0; /* add if necessary */
}

Trust this solution brings you success

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What's the best way to ensure that my image remains perfectly centered at the point where the background colors of my

html <body> <header> <div class="indexHeaderWall" id="headerLeftWall"> </div> <img id="profilePic" src="icons/myPicture.jpg" alt="Picture of Daniel Campo ...

Ways to display an icon in Angular 10 only when it is hovered over

Just getting started with Angular and still learning the concepts. Trying to figure out how to show an icon only when it's hovered over. Can anyone assist me? Sorry, can't share the code because of company rules. The icons are for sorting and ...

Storing and sharing information between routes in Angular 2: The ultimate guide

As I launch my angular app, I make a request to an endpoint during initialization to retrieve data for specific routes. When I navigate to the home page, I fetch the home page data from the database and return it. Similarly, when I go to the contact route, ...

Restrict the height of a division based on the adjacent division

Within the parent div, I have two child div elements that are meant to be positioned side by side. The first element contains an image which loads dynamically, meaning its height is unknown in advance. I want the parent div's total height to match the ...

User Interface showcasing real-time progress data pulled from API

Currently, I am facing a situation where there are three docker containers involved in my project: - An angular frontend - A Django backend - A Python processing API The scenario is such that a user uploads a file to the backend volume through the fronten ...

A guide on exporting table data to PDF and enabling printing features in Angular 7

Can anyone provide guidance on how to export my dynamic table data into Excel, PDF, and for printing using the appropriate Angular Material components and npm plugins? I have successfully exported the data as an Excel file, but am struggling with exporti ...

Achieving Perfect Alignment for Absolutely Positioned Divs in

I'm currently facing an issue where the image I'm trying to center horizontally also moves the parent div downward when I try to vertically center it using top-margin. This is not the desired outcome. If you'd like to see what I mean, I&apo ...

Angular 2 testing error: Unable to connect to 'ngModel' as it is not recognized as a valid property of 'input'

Currently, I am experimenting with angular2 two-way binding for the control input. Below is the issue that I encountered: An error occurred: Can't bind to 'ngModel' since it isn't a known property of 'input'. Contents of app. ...

Ensures that two divs have the same dimensions

Currently, I have a line of sections set up like this: I am attempting to ensure that the second div matches the height of the first one, despite the fact that their heights are determined by the size of the pictures which may vary. Do you have any sugges ...

Angular with Entypo Icons

If you want to use the Entypo SVG icon set in your Angular application, you will need to add some JavaScript to the page. Here is an example of how you can do this: const entypo = require('entypo') document.body.insertBefore(entypo.getNode(), d ...

What could be causing the whitespace around this element when using SASS from Refills / Bourbon.io?

I've recently started using the impressive SASS framework, Boubon.io created by the talented team at thoughtbot. As I experiment with their supplied templates (known as Refills), I'm finding that Bourbon.io serves as a versatile alternative to po ...

iOS devices are experiencing issues with touchstart and touchend events not functioning when utilizing jquery mobile and cordova

During a previous project, I encountered no problems with the following code snippet. It effectively utilized touchstart and touchend events to adjust the CSS of a button: <script> $('input[type="button"]').on('touchstart', func ...

I have come to realize that my understanding of how Sass nesting works was misguided

Currently struggling with understanding Sass nesting. Any explanations on where I went wrong would be greatly appreciated, as this is a beginner-level issue for me. Thank you in advance. .header { display: flex; height: 10vh; background-color: #13192 ...

What is the best way to add color to a Table Header?

I'm working on a HTML/CSS table and I want the header row to have a specific background color. Below is my code: <table class="contentTable"> <tr class="contentTableHeader"> <th>No.< ...

Angular - Loading images on the fly

After scouring numerous resources, I couldn't find a resolution to my issue. For your information, I am utilizing ASP.net Core 2.0's default angular project In the process of developing an Angular application, I am faced with the challenge of ...

Tips for managing ngcli once you have ejected the webpack configuration

I am looking to customize the webpack pack build within an Angular cli project. To make these configurations, I decided to eject the webpack config file. ng eject However, once I have ejected the file, I encounter an error when trying to run the webpack ...

Tips for styling buttons in react-admin with custom CSS

I need some help with customizing buttons in react-admin. I am new to the platform and unsure about how to go about changing the button CSS for various actions such as create, edit, and export. Can anyone provide guidance on the best way to customize these ...

What is the best way to toggle the visibility of the ng-bootstrap datepicker-popup component?

Is there a way to toggle the visibility of the ng-bootstrap datepicker-popup by setting a property to 'true' or 'false'? In my form, I have the following snippet and I only want to show the entire div section if the user chooses to inp ...

Expand a section of the background picture

I am working with an image that contains multiple flag images: https://i.stack.imgur.com/xg0iM.jpg I have a div element with the dimensions: width:100px; height:50px. My goal is to resize each flag to fit inside it: .flag{ wi ...

Experience the latest happenings in SAP Spartacus 4.0 by signing up for updates directly from

I am facing an issue while trying to register an event in Spartacus import { Injectable } from '@angular/core'; import { CartDetailsComponent, PromotionService} from '@spartacus/storefront'; import { ActiveCartService, SelectiveCartServ ...