Tips for altering the label color of an md-input-container after text has been entered

Is there a way to dynamically change the color of an md-input-container label after certain input is added? The default grey color gives the impression that the field is disabled. I specifically want to modify the color of the label "Description" when the input field is no longer empty. I attempted to adjust the styling in the CSS using the following code, but it did not produce the desired effect:

md-input-container.md-default-theme label,   
md-input-container.md-default-theme .md-placeholder {  
    color: #FDFE67 !important; 
} 

Below is the relevant HTML code:

<div ng-app="MyApp" ng-controller="DemoCtrl" layout="column" ng-cloak="" class="md-inline-form inputdemoBasicUsage">
  <md-content layout-padding="">
    <div>
      <form name="userForm">
        <md-input-container class="md-block">
          <label>Input-autofocus</label>
          <input ng-model="user.firstName" type="text" autofocus>
        </md-input-container>

        <md-input-container class="md-block">
          <label>Input-md-autofocus</label>
          <input ng-model="user.title" type="text" md-autofocus>
        </md-input-container>
      </form>
    </div>
  </md-content>
</div>

And here is the AngularJS code snippet:

angular
  .module('MyApp', ['ngMaterial', 'ngMessages'])
  .controller('DemoCtrl', function($scope) {

  });

If you'd like to view the code in action, it's also available on CodePen: http://codepen.io/zcook/pen/bpxGWJ

Answer №1

To achieve a label color change upon input, you can implement the following CSS code...

.custom-form input[type="text"].filled label {
  color: blue;
}

If you prefer the label color to change after the user enters input and removes focus, you can utilize the following CSS code...

.custom-form input[type="text"].filled:not(:focus) label {
  color: blue;
}

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

Ways to transfer data from TypeScript to CSS within Angular 6

Trying to work with ngClass or ngStyle, but I'm struggling with passing the value. Here's my current code: strip.component.ts import { ... } from '@angular/core'; @Component({ selector: 'app-strip', templateUrl: &apo ...

The alignment of my card icons changes depending on the size of the paragraph

Here are my cards I am attempting to give them a relative position and the parent div an absolute position, but it is not working as expected. Despite several attempts, I still cannot get the desired result of positioning the cards correctly within the p ...

Embracing Micro Front End Development

Currently, I have a legacy AngularJS (Angular 1) app that cannot undergo any major changes at the moment. A new standalone app has been created using a newer stack. The goal is to integrate this new app into the old legacy app without making significant m ...

"An error of ElementNotVisibleError was encountered even though the element is visible

For the past day, I've been trying to solve this issue. While performing end-to-end testing, I encountered an error when attempting to click on a visible element in the browser: ElementNotVisibleError: element not visible Strangely, the ele ...

Tips for troubleshooting the Gulp error "Encountering [proxy] Error: getaddrinfo ENOTFOUND"

I'm facing an issue while trying to resolve this with gulp serve: [proxy] Error: getaddrinfo ENOTFOUND Check out the screenshot below: https://i.sstatic.net/GbbzW.png ...

Having trouble achieving the desired effect with inline block

I'm having some trouble creating a simple store page. One of the products is supposed to look like this: https://i.sstatic.net/JLlua.png However, it's currently showing up like this: https://i.sstatic.net/hHYUm.png I've been attempting t ...

The Mui Switch track color fails to change when checked

I'm looking to customize the colors of the track for both checked and unchecked states. Currently, the track color is working for the unchecked state but defaults for the checked state: Checked State: https://i.stack.imgur.com/eGV4a.png Unchecked S ...

Arranging buttons that are generated dynamically in a vertical alignment

Currently, I am in the process of creating a webpage for various items, and everything is going well so far. However, I have encountered an issue while attempting to vertically align the buttons that I am generating using JavaScript within the document. I ...

Is it common for the external template to remain incompletely compiled during the execution of the directive's link function?

Let's consider a hypothetical directive called myDirective: <my-directive></my-directive>. Once compiled, it should be replaced by an external template like this: <my-button>MyButtonLabel</my-button> This my-button is expe ...

Position divs to be perfectly aligned and centered

I'm in the process of creating a webpage and facing challenges with aligning my divs properly, specifically the animated company logos. I want them to be positioned side by side rather than on top of each other, with space in between to fit the layou ...

Issue with MUI Grid item not functioning properly when using overflowY: "auto"

I am encountering an issue while using MUI with React. I have a <Paper> element wrapping a <Grid> with 3 children elements. The problem arises when I set the overflowY property of the bottom grid item to "auto" - instead of showing the scroll b ...

Attempting to emulate the grid showcase using flexbox styling

Creating this layout using CSS Grid was a breeze. However, I wonder if it can be achieved with Flexbox. What do you think? .Message { display: inline-grid; grid-template-areas: ". name""date text"; } .Date { align-items: ...

Verifying that the class name prefix aligns with the folder name using Stylelint

Currently, I am utilizing the "selector-class-pattern" rule from stylelint. My chosen pattern enforces the ECSS naming convention. The specific rule configuration is outlined below: "selector-class-pattern": ["^[a-z]([a-z0-9]){1,3}-[A-Z][a-zA-Z0-9]+(_[A-Z ...

The HTML embed element is utilized to display multimedia content within a webpage, encompassing

Currently, I am working on a static website for my Computer Networks course. Students need to be able to download homework files in PDF format from the website. I have used embed tags to display the files online, but I'm facing an issue where the embe ...

Twice within a controller, alert is displayed in AngulasJS, OnsenUI, and Phonegap

I'm currently developing a mobile application using AngularJS, OnsenUI, and PhoneGap to package it for Android devices. However, I've encountered a strange issue where an alert box pops up twice when the application is run as a new process. I&ap ...

invoking an API within a map function and utilizing the response

vm.owners = parents.children.map(function(e) { getparentById(e.Id) .then(function(getresponse) { var parentLink = '<a href="/#/parent/onboard/' + e.Id + '" target="_blank">' + e.Number + "-&qu ...

Issue with Angular Script not functioning upon reopening the page

I recently completed my first website, which can be found at Despite my efforts, I've encountered an issue that has me stumped. When you navigate to the certificate page, you should be able to input your name onto the certificate. However, if you sw ...

When the screen size changes, the centrally aligned position of sticky elements does not stay consistent

It has come to my attention that when centrally aligning an element with position sticky, the alignment can start to malfunction upon reducing the screen width past a certain point, depending on the width of the element. Unlike position: fixed, the sticky ...

Safari shows a contrasting outcome

Having an issue with compatibility in the safari browser You can check out the site here: The problem lies with the text inside the image, I want it to display properly like it does in Chrome. Here is the desired result for Safari as well. Below is the ...

Implementing a Scroll Bar within a Stack Component in Material UI

I've developed a component and now I'm looking to enable scrolling when it expands beyond the screen width <Stack direction="row"> <Stack gap={1} overflow="auto"> {fields.map((el, i) => ( ...