:autofill
Baseline 2023Newly available
Since February 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Die :autofill CSS-Pseudoklasse wird angewendet, wenn ein <input>-Element seinen Wert vom Browser automatisch ausgefüllt hat. Die Klasse endet, wenn der Benutzer das Feld bearbeitet.
Probieren Sie es aus
Hinweis:
Die Benutzeragent-Stylesheets vieler Browser verwenden !important in ihren :-webkit-autofill Stil-Deklarationen, was bedeutet, dass sie von Webseiten nicht überschrieben werden können, ohne auf JavaScript-Tricks zurückzugreifen. Zum Beispiel hat Chrome Folgendes in seinem internen Stylesheet:
background-color: rgb(232 240 254) !important;
background-image: none !important;
color: -internal-light-dark(black, white) !important;
Dies bedeutet, dass Sie in Ihren eigenen Regeln background-color, background-image, oder color nicht festlegen können.
Syntax
:autofill {
/* ... */
}
Beispiele
Das folgende Beispiel zeigt die Verwendung der :autofill Pseudoklasse, um den Rahmen eines Textfeldes zu ändern, das vom Browser automatisch vervollständigt wurde.
Um sicherzustellen, dass wir keine ungültige Selektorliste erstellen, werden sowohl :-webkit-autofill als auch :autofill mit einer toleranten Selektorliste unter Verwendung von :is() abgeglichen.
input {
border-radius: 3px;
}
input:is(:-webkit-autofill, :autofill) {
border: 3px dotted orange;
}
<form method="post" action="">
<label for="email">Email</label>
<input type="email" name="email" id="email" autocomplete="email" />
</form>
Spezifikationen
| Specification |
|---|
| HTML Standard # selector-autofill |
| Selectors Level 4 # selectordef-autofill |
Browser-Kompatibilität
BCD tables only load in the browser
Siehe auch
- Chromium Issue 46543: Auto-filled input text box yellow background highlight cannot be turned off
- WebKit Bug 66032: Allow site authors to override autofilled fields' colors.
- Mozilla Bug 740979: implement
:-moz-autofillpseudo-class on input elements with an autofilled value - User Interface Module Level 4: more selectors