0

I want to know if there is any way to add asterisk after first option of select element?

Here is my html

<select class="form-control textyformcontrol">
   <option selected>Service area</option>
   <option>First Option</option>
   <option>Second Option</option>
   <option>Third Option</option>
</select>

Here is css

.textyformcontrol {
    outline: none !important;
    box-shadow: none !important;
    border: none !important;
    border-bottom: 1px solid #fff !important;
    background: transparent;
    border-radius: 0px;
    color: #fff;
    font-size: 16px;
    padding: 10px 0px;
    word-spacing: 2px;
    height: auto;
}

All the options are having default white color.Thus how to add asterisk in red color through css?

M Hamza Javed
  • 1,261
  • 4
  • 15
  • 30
Shashank Bhatt
  • 613
  • 9
  • 22

1 Answers1

0

The following solution adds a red asterisk to each option element that does not have the selected attribute:

.textyformcontrol option[selected]:after {
  content: "";
}

.textyformcontrol option:after {
  content: "*";
  color: red;
}

Please see my demo here.

Ralph David Abernathy
  • 4,879
  • 9
  • 47
  • 72