![]() |
| ||
| Forms: styling text fields with CSS and HTML 1 Attachment(s) Although forms are one of the most boring elements of any website, styling them can be a dangerous business. All too often it is forgotten that the way a form looks will impact greatly upon what the user uses it for. Change the style too drastically and the user might not recognize it as a form at all. In this tutorial you will learn how to style the text field element just enough to make it look good but without ever detracting from the fact that it has to be easily recognizable as a text field from a form. You will require the following software before you begin:
You must also create a new HTML file, within which you need a form and then a text field. Your html should look like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> You now have to add a class to this text field, which you could do using the "selector" "input" but this would style every single type of input on your page. Instead, you should put the following code inside each of the "input" tags: class="textfield_effect".OK, you are now finished with HTML for the time being. Now you can move on to creating a CSS file. The properties you are going to be playing around with are:
Instead of explaining each tiny bit of CSS, this tutorial will just show you it from there you should be able to understand what has been done (the CSS is commented to help you with this.) /* CSS Document */ Next you must attach the CSS file to the HTML file by adding this code in the head of your HTML file: <link href="style.css" rel="stylesheet" type="text/css" />Now add a title to the form element but instead of adding it on the outside of the text field you are going to put the text inside the text field. All you need to do is add this piece of code to the "input" tag: onfocus="this.value=''".The only other thing you need to add is the submit button! A word of warning though, this is an element that should not be styled because it looks very different in different operating systems! And that is the end of this tutorial, you should now have been able to create something that looks like this: Attachment 2908 |
| ||
| Re: Forms: styling text fields with CSS and HTML Hello Roryt, Forum Members, To minimize the differences of all elements in different browsers, you can add: * {padding: 0px; margin: 0px} to your style sheet. This eliminates the default margins and padding for everything. Elements like for H1, h2..., <li> <input>, etc. have different styles in different browsers. This starts you off with a level playing field. You'll have to go back and add some margins and padding to elements you didn't have to style before however! Peace |
| ||
| Re: Forms: styling text fields with CSS and HTML Hello Forum Members, Congratulations to the author(s) of this excellent tutorial, clean and simple, but i think that it would be COMPLETE if it includes all the files related -code, images, etc.- in a zip file to be able to download. Best regards, |
| ||
| Re: Forms: styling text fields with CSS and HTML I wanted you to learn something from this tutorial not just download the files.. sorry ;) |
| ||
| Re: Forms: styling text fields with CSS and HTML Quote:
I also think you should have included the files, or at least a demo page. How is a new developer supposed to 'grade' their version against your version. |
| All times are GMT -4. The time now is 6:47 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC