W3docs

Pseudo-classe CSS :enabled

Usa la pseudo-classe CSS :enabled per selezionare e applicare stili agli elementi abilitati. Scopri la pseudo-classe ed esercitati con gli esempi.

La pseudo-classe CSS :enabled seleziona e applica stili agli elementi abilitati.

Questi elementi sono di solito elementi di form, come i pulsanti (<button>), i menu a tendina (<select>), i tipi di input (<input>) e le textarea (<textarea>).

Gli elementi abilitati accettano clic, immissione di testo o focus.

Versione

HTML Living Standard

HTML5

Selectors Level 4

Sintassi

Esempio di sintassi CSS :enabled

:enabled {
  css declarations;
}

Esempio del selettore :enabled:

Esempio di codice CSS :enabled

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      input {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        padding: 2px 5px;
      }
      input[type=text]:enabled {
        background: #eee;
      }
      input[type=text]:disabled {
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <h2>:enabled selector example</h2>
    <form action="#">
      <label for="name">First name:</label>
      <input type="text" value="John" id="name" />
      <br />
      <label for="lastname">Last name:</label>
      <input type="text" value="Smith" id="lastname" />
      <br />
      <label for="country">Country:</label>
      <input type="text" disabled="disabled" value="10 High Street" id="country" />
    </form>
  </body>
</html>

Esempio del selettore :enabled con il tag <option>:

Altro esempio di codice CSS :enabled

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      option:enabled {
        background: #666;
      }
    </style>
  </head>
  <body>
    <h2>:enabled selector example</h2>
    <select>
      <option value="paris">Paris</option>
      <option value="london" disabled>London</option>
      <option value="moscow">Moscow</option>
      <option value="rome" disabled>Rome</option>
      <option value="berlin">Berlin</option>
    </select>
  </body>
</html>

Pratica

Pratica
What does the ':enabled' pseudo-class in CSS do?
What does the ':enabled' pseudo-class in CSS do?
Was this page helpful?