Content of the lesson:
If you start creating web applications you find out that the standard appearance of the form elements is efficient and transparent (if the form is alone in the page) but when you need to visually design the form inside your page you will face several problems.
CSS does not have any prescriptions for form elements because it is not clear whether these elements have to take the system appearance or take the browser appearance. Although there is no prescription several browsers allow you to use styles when placing forms into you page.
Some webdesigners recommend not to style form elements at all. If you want to use a form on your blog which contains only a few elements and you need it to function in every browser without any problems, you should not use CSS styling. Nevertheless, if you create a gentle design and have the possibility to test your form in different browsers, it can improve the impression of your page.
If you create a page for intranet (what is intranet) you face a different situation. These pages usually contain tens of hundreds of forms or have to be inserted inside a complex table. Non-styled pseudo-3D form elements take too much place and their appearance is ancient.
Form using this CSS modification for the form element
A form should use one font only. However, the font cannot be inherited from body or html and you also cannot set one font for the form. To get the following result you have to use these rules:
input, select, textarea {font: normal 100% Tahoma, SansSerif, Verdana;}
If you want to make the appearance even more uniform, you can use additional CSS styling for elements like label, fieldset, legend etc.
This element (<input type="text" ... />) is the most used one in forms. It is used to insert shorter text like names, addresses, dates etc.
Now we are going to change the appearance of the text input box which is functional in almost every browser. The main task is to eliminate the pseudo-3D effect of this element. The styled element can be inserted into a container (into a div for example) which will use the design we want.
width: 140px;
height: 18px;
margin:0;
padding: 0 1px 0 0;
background:#ff9;
border: 1px solid #666;
font: normal 100% Tahoma, SansSerif, Verdana; /* Why we use
this rule when it has already been defined in the form element? */
Note to the size attribute of the input box: this is an older way to define the size of the form element. The size will not be the same in every browser so it is much better to use the CSS properties.
The element textarea is used for longer, multiline texts, usually of previously unknown length. Textareas can be used to create boxes for comments, questionnaires etc.
Now we are going to change the appearance of the textarea element which is supported by almost every browser. The main task is to eliminate the pseudo-3D effect of this element. The styled element can be inserted into a container (into a div for example) which will use the design we want.
width: 260px;
height: 50px;
margin: 0;
padding: 0;
background: #ffa;
border: 0;
overflow-y: scroll; /* scrolling boxes will appear only if
needed */
font: normal 100% Tahoma, SansSerif, Verdana;
Note to the rows and cols attributes: they set the number of rows and columns of the textarea item. This is an older way to define the size of the textarea element. The size will not be the same in every browser so it is much better to use the CSS properties.
The select element is used to choose from several options or for a simple menu.
This element appears very differently in each browser. We should only change the font to be uniform with the other form elements, additionally the background color and the border (the border is not correctly drawn in all browsers). We can set the height and the width but we have to assure that the content is readable. In this case we set only the width.
width: 260px;
background: #ffa;
border: 0;
font: normal 100% Tahoma, SansSerif, Verdana;
The elements checkbox and radio are used for choosing an option and it is better not to style them at all. End.
An interesting solution can be realized using these elements and javascript (more at this address: http://swatelier.info/at/formulare/checkBox.htm in section "Experimental checkbox").
The form element input type="submit" is used to send the form to the server.
width: 100px;
height: 22px;
background-color: #c6362d;
color: #fff;
border: 2px solid #912522;
font-weight:bold;
padding-left: 5px;
padding-right: 5px;
cursor:pointer;
font: normal 100% Tahoma, SansSerif, Verdana;
Submit button can be improved by adding a background image or a dynamic effect after moving mouse cursor over the button (it can change color for example).
Create a nicely designed www page with a form and use CSS styling (in an external CSS file). Add a background image and a dynamic effect to the submit button.