XML technologies / CSS / CSS Cookbook / Forms / Different styles for different input elements in one form
(Excerpt from “CSS Kochbuch” by Christopher Schmitt)
Problem
The input elements (input) in one form should have different styles.
Solution
Use two or more class selectors to assign the different styles.
First, give the input elements class attributes:
<label for="fmname">Name</label>
<input type="text" name="fmname" class="fmname" />
<label for="fmemail">Email</label>
<input type="text" name="fmemail" class="fmemail" />You can then target the input elements in the stylesheet using the value of class:
.fmname {
text-align: left;
}
.fmemail {
text-align: center;
}Discussion
Using class attributes to assign the same styles to several elements on a page works in most browsers.
Another way to assign custom styles to particular elements is available in browsers that already understand the CSS 3 specification for attribute selectors, as discussed in the recipe Adjusting link colours.
See also
The recipe Styling buttons on defining different styles for different buttons in one form.
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