Customize the text color of select list options in Angular 5

Is there a way to style the foreground colors of select list options differently in this dropdown code?

<select id="tier" class="form-control" [(ngModel)]="tierId">
    <option *ngFor="let m of tierList" value="{{m.tier}}" >
        {{m.optiontext}} | {{m.count}} 
    </option>
</select>

I would like the optiontext to be displayed in blue and the count in red. Any suggestions on how I can achieve this customization?

Answer №1

The standard <select> element does not have the capability to display multiple colors within its options.

If you need this functionality, consider using a library like @angular/material.

Here is an example:

<mat-select id="tier" [(value)]="tierId">
  <mat-option *ngFor="let m of tierList" [value]="m.tier">
    <span style="color: blue;">{{m.optiontext}}</span> |
    <span style="color: red;">{{m.count}}</span>
  </mat-option>
</mat-select>

For further details, visit

Answer №2

<!DOCTYPE html>
<html>
   <head>
      <style type="text/css">
         option.red {
             background-color:red
          }
         option.blue {
             background-color:blue
         }
         option.white {
             background-color:white
         }
      </style>
   </head>
   <select>
      <option value="item 1" class="red">Item 1</option>
      <option value="item 2" class="blue">Item 2</option>
      <option value="item 3" class="white">Item 3</option>
   </select>
</html>

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

Having trouble getting the carousel slider to function properly on meteor?

I am currently working on my portfolio page using Meteor, and I want to include a carousel slider gallery. The problem I'm facing is that while the first gallery works fine, the second one does not load correctly and just displays a list of pictures. ...

Dynamic Data Display

I'm experiencing an issue where the data is not displaying in the table div when using an Ajax call to load the table. The page appears blank upon return, and I have tried using $('#groupTable').load(data); without any success. If anyone can ...

Generating an HTML report that includes a header and footer on every page using Firefox

I have been trying different methods, but none of them seem to work properly. My issue is with printing a html report with a header and footer on every page specifically in Firefox. A Possible Solution: <html> <head> <title></title&g ...

Waveform rendering in HTML5 using wavesurfer.js struggles to handle large mp3 files

Recently, I was considering incorporating wavesurfer.js into one of my projects so I decided to explore the demo on To test it out, I uploaded a large mp3 file (approximately 2 hours long) onto the designated area in the middle of the page. It appeared to ...

Automatically generate a file path for imports using the class name

When working on my angular 2 application in Visual Studio, I often wish there was a way to automatically populate the import path similar to how C# uses statements work with the 'ctrl .' key combination. Typing out imports repeatedly can be tedio ...

Manipulate the value of the <input> element when focused through JavaScript

After I focus on the input field, I was expecting to see Bond-Patterson, but instead, I am only getting Bond. What could be causing this discrepancy and how can it be fixed? $('input[name="surname"]').attr("onfocus", "this.placeholder='Bo ...

Issue with Hover Effect on Safari Browser

Encountering a peculiar issue exclusively in Safari - when hovering over a link in the header, the links to the right of the hovered-over link alter their size (appearing smaller) during the hover animation. Once the animation concludes, these links revert ...

Utilize Angular 2 interceptor to incorporate HTTP requests

Dealing with the 401 response from an interceptor using the HttpClientModule in Angular and JWT authentication can be a bit tricky. When the accessToken expires, it's necessary to use the refreshToken to obtain a new one before making the actual API r ...

Modifying form data when submitting a form

Is there a common or widely-used method for modifying or adding form values before they are serialized and sent to the server upon form submission? I'm looking for a way to change or add these values without having to recreate them. I've come ac ...

Consecutive pair of JavaScript date picker functions

My issue involves setting up a java script calendar date picker. Here are my input fields and related java scripts: <input type="text" class="text date" maxlength="12" name="customerServiceAccountForm:fromDateInput" id="customerServiceAccountForm:from ...

The NgbTooltip does not activate when hovering over a <td> cell

I'm currently facing an issue with implementing ngbTooltip on <table> elements. Initially, I had trouble with <th>, but that was resolved by using the container attribute after referring to this helpful post. The main challenge arises ...

Tips for developing a collaborative service for utilization across numerous Angular applications

Is it feasible to develop a shared service that can be utilized in numerous Angular applications? And if so, how? For instance, similar to how we create an Angular library that can be accessed externally by packaging it into an npm package. Is it possible ...

Is Javascript the best choice for managing multiple instances of similar HTML code?

I am currently facing the challenge of dealing with a lengthy HTML page consisting of around 300 lines of code. The majority of the code involves repetitive forms, each identical except for the ID (which varies by number). Is it considered appropriate or ...

Tips for aligning two separate texts depending on if they appear on the same line or not

Looking to align text B to the right when text A and B are on the same line, but automatically aligning text B to the left if it wraps to the next line due to space constraints. .text-left { float: left; /* Float to the left */ } .text-right { fl ...

What is the best way to conceal text that is not enclosed in <p> or <span> tags?

I need to hide a specific portion of text in an HTML code snippet, however, the text is not wrapped in any specific element. Here is an example: <div class="content"> Give comfortable and durable place to work with a desk. Lock the center d ...

Another option instead of preloading images

Currently, I am in the process of creating a jQuery slideshow. After reviewing numerous tutorials on the subject, it appears that most recommend preloading images using code similar to the following: imageArray[imageNum++] = new imageItem(imageDir + "02. ...

Learn how to incorporate a YouTube video into your website without using Flash or JavaScript by utilizing a popup window

I am in search of assistance with coding for my website to include a video popup feature featuring a YouTube video. I prefer the use of HTML5 rather than Flash or JavaScript. Unfortunately, I have been unable to locate any suitable code examples. While I ...

Testing services in Angular that rely on TranslateService with unit tests

How should I utilize the TranslateService in unit tests for a service? The TranslateService is typically used in the service class like this: export class ErrorControllerService { constructor(public translate: TranslateService) { } ... } I at ...

Why is my client program not receiving a response from this socket.io server?

Currently, I am in the process of developing a trivia game where two users engage in answering questions with the winner being declared at the end. As part of this project, I have integrated socket.io to facilitate the exchange of answers. However, I have ...

Design a dynamic card with an eye-catching Font Awesome icon that adapts well to

As I delve into the realm of CSS, my current mission is to replicate the captivating cards showcased on this particular website. Utilizing Font Awesome icons has become a pivotal aspect of this endeavor. For instance, let's take a look at this card:ht ...