Create HTML form using lists and css/html
Why html lists to create html forms?
With this post i will take you through how to create html forms using HTML lists. It will be a form a system may use for data collection. For example it can be a registration form, contact form, login form, customer registration form or sales order form etc. It can be one of many forms that we have come across day to day browsing.
A sample html form
Web developers use various methods to code and apply design to html forms. HTML coders cut-up photoshop designs into tiny images and code them into css/xhtml layouts, Many web developers prefer using standard html tags to code html form. This post will demonstrate how to use HTML list with greater effect on building your html form layouts.
Power of html lists are huge, I would say lists can even replace DIVs. Some html coders think html lists are there only to show bullet point content and menus, Wrong assumption I guess. Some coders even find the default behavior of html lists are different to than other html tags. This makes list bit hard to code in css.
Let us look the power of HTML Lists. Lists give more control in html code and in return lists gives less troubles when it comes to browser compatibility. You need to learn default behaviors of html lists before you using it for coding, Such default properties are bullet pattern, margin and padding. Before you use html list for regular html coding it requires you to get ride of these default properties using css.
Most html coders prefer to use DIVs and fieldset html tags to create html forms for data capturing.
But lists will furnish you more control on coding this kind of HTML form layouts, Lists acts like a replacement for html tables.At WeCodeYourSite we do lot of research into this and so far it is real successful. One of the success was using html lists to create html forms.
By using HTML Lists you can code html forms very quickly like in html tables. Once you make list to behave like html tables it is just a matter of copy & paste, like we did html tables.
Let’s dig into how to code a real world html form layout using the code snippet below,
</ul> <li> <input id="txtDiscount" type="text" /></li> <li>Address :</li> <li> <input id="txtAmount" type="text" /></li> <li></li> <li> <input id="Text1" type="text" /></li> <li></li> <li> <input id="Text2" type="text" /></li> <li>City</li> <li> <input id="txtDisAmt" type="text" /></li> <li>State</li> <li> <input id="txtNetAmt" type="text" /></li> <li>Notes</li> <li> <textarea id="Text3" rows="5" cols="30" ></textarea></li> <li></li> <li> <input id="Submit1" type="submit" value="Send" /></li> </ul>
How to arrange list to create a html form?
The above html code snippet will produce a simple registration form, a very basic one.The html code is simple and strait forward. As you can notice how simple lists in html code, Let us look how this code operate with the browser. As we all know list elements(<li> tags) are surrounded by another html tag(<ul> tag). This tag will be acting as a container for all the list items. It is something similar to field-set tag. As you can recall a registration from you have use before, it had labels to say name of the input and on the other site the input text box or drop down is placed to capture the data input. This layout something similar to a two column table. So each row need two cells, with lists we need two list items to create the required row structure. As you can notice in above code I have placed the labels in one list item and followed with a the input control. Now html structure in place let us look at the css styles which will make the above html code professional html form.
Look how simple the css/xhtml code.
Let me explain what each css/xhtml style does.
As we all aware that the unordered list(ul) tag will be the parent control tag, it will going to grip all the list items together.
By using style property value none for list style type we can take away bullets that comes default for unordered lists or ordered list(the other counterpart list).
Remember both unordered list(ul) plus ordered list(ol) tags by default you has set to 20 pixel margin and 20px padding. For some browsers it acts as padding for some it acts as margin.
If you don’t need default padding and margin, you be able to remove default margin and padding by setting to 0 pixel for both under unordered list style property.
This default margin padding of ordered lists Confuse most of css coders, at the beginning of their career.
Any html form has a defined width. In this case form container will be the ul tag. By setting a width to it we can set the form width. The float property is necessary to keep the floated list items within the same row together, list item top margin will keep the gap between form controls.
Here I have used an ordinary width for the list item that is the width of the form labels.
Last css/xhtml style is to override the default width of the list item to accommodate more space to input controls.
If you look at overall html and css it is very simple and easy maintain. You can find the complete sample of how to create html forms using lists
More by this Author
Jquery client-side validation for Email Address on HTML forms. Article will show how to use regular expressions and JQuery to validate email address on client-side.
This tutorial will show you how to load Google Map into Jquery Dialog box. Tutorial guide you how to use google map API to create maps and address points on it.
How to create a fluid gradient box using css/html. Article will guide you step by step how to slice your gradient box and create the css sprite images to optimize the html code.