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

Joined
Sep 4, 2022
Messages
163
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
607
Reaction score
81
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>
 
Joined
Sep 4, 2022
Messages
163
Reaction score
16
Thank you very much VBService , I was in a lost battle , searching to achieve by all 'option' tags .
Thank you again ! :)
 

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

No members online now.

Forum statistics

Threads
474,342
Messages
2,571,416
Members
48,794
Latest member
massivestack

Latest Threads

Top