ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

Create HTML form using lists and css/html

Updated on May 4, 2016

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

a sample html form
a sample html form | Source

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.

ul{list-style-type: none;float:left;width:400px;}

ul li{float:left;width:150px;margin-top:10px;}

ul li.input{width:250px;}

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

Comments

    0 of 8192 characters used
    Post Comment

    • nnjiru profile image

      nnjiru 

      5 years ago

      Good tutorial. To see about calculating using form and JavaScript follow the link;

      https://hubpages.com/technology/Calculations-using...

    • wecode profile imageAUTHOR

      wecode 

      5 years ago from Australia

      thx for reading....! but sorry mate this is my way thx for u'r suggestions

    • profile image

      mtt 

      5 years ago

      I read, and it is really crappy and dirty way to do it.

      You already have labels and input tags, why the hell would you add li tag over it ?

      I gave a correct way to do it on my previous comment.

    • wecode profile imageAUTHOR

      wecode 

      5 years ago from Australia

      Please read the code carefully .... it uses two li tags. One for the label text and the other to hold the input box.... the article is about how to use ul li tags to build html form not labels.....

    • profile image

      mtt 

      5 years ago

      Omg, it's really crappy !

      You don't even use labels ! and using 1 li by elements is against the lists semantic !

      a good way should be :

      [li][label for="foo"]foo[/label][input type="text" id="foo"][/input][/li]

      And this thing is in first google page...

    working

    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, hubpages.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://hubpages.com/privacy-policy#gdpr

    Show Details
    Necessary
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
    Features
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Marketing
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Statistics
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)