Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding”Download now!
Web Forms - Styling Forms
(Page 6 of 9 )
Now that we have a nicely structured form, let’s uncover a few CSS techniques we can use to customize it visually.
Setting the width of text inputs
Form controls can be tricky to deal with in their varying widths and heights that are dependent on browser type. In our form example, we haven’t specified a size for the text inputs and have left the width of these up to the browser’s defaults. Typically, a designer might specify a width using the size attribute, adding it to the <input> tag like this:
Setting a size of "20" specifies the width of the text input box at 20 characters (and not pixels). Depending on the browser’s default font for form controls, the actual pixel width of the box could vary. This makes fitting forms into precise layouts a tad difficult.
Using CSS, we can control the width of input boxes (and other form controls) by the pixel if we wish. For instance, let’s assign a width of 200 pixels to all <input> elements in our form example. We’ll take advantage of the id that is assigned to the form, in this case thisform.
#thisform input { width: 200px; }
Now, all <input> elements within #thisform will be 200 pixels wide. Figure 5-9 shows the results in a visual browser.