XML technologies / CSS / CSS Cookbook / Forms / Highlighting input fields
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
The form input field currently used by the user should be visually highlighted.
Solution
Use the pseudo-class :focus. The following CSS rule changes the background colour of the currently used input element (see the following figure):
input:focus {
background-color: yellow;
}Figure: The currently selected input field’s background colour changes.
Discussion
The following browsers support the pseudo-class :focus: Netscape Navigator 6+, Firefox, Safari and Opera 7. Browsers without support for :focus simply ignore the corresponding rules, ensuring backward compatibility.
See also
The recipe Styling textarea elements on styling textarea elements, and the table Overview of CSS properties for multiline input areas under Styling form elements.
Copyright of the German edition © 2007 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “CSS Kochbuch” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln