Css for one "select option" box , "valid" and "invalid"

Joined
Sep 4, 2022
Messages
151
Reaction score
16
Hello helpers

I'm struggling with a 'select option' box , with applying Css ,

from 'load' , to 'one option selected' , I get on with a JQuery switcher using 'onChange()' function as event.
But I think CSS have one effiscient solution for my case.


HTML:
<select id="sel-box">
    <option disabled>Choice :</option>
    <option value="1">A</option>
    <option value="2">B</option>
</select>


I aim for a full CSS use, so making this select tag and its options beautiful , as one option is selected.
It's around 'valid/invalid' , to throw out a switching JQuery implementation for now.

thanks in advance , thanks for your time and support :)
 
Joined
Jul 4, 2023
Messages
577
Reaction score
77
Do you mean something like this?
HTML:
<select id="sel-box" required>
  <option value="" disabled selected>Choice :</option>
  <option value="1">A</option>
  <option value="2">B</option>
</select>

<style>
  select:invalid {
    border: 2px solid red;
    animation: pulse 1s infinite alternate;
  }

  select:valid {
    border: 2px solid green;
    animation: none; /* Stop animation when valid */
  }

  @keyframes pulse {
    0% {
      box-shadow: 0 0 5px red;
    }
    100% {
      box-shadow: 0 0 15px red;
    }
  }
</style>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,306
Members
47,953
Latest member
TrinidadV1

Latest Threads

Top