How to create a form with div + css maintaining the xhtml semantic structure

Source: Internet
Author: User

In form, we can group and classify information in form. For example, in form of registry form, we can divide registration information
Basic information (required generally)
Details (optional)
So how can we achieve it better? We can consider adding the following two tags to the form:
Fieldset: groups forms. A form can have multiple fieldsets.
Legend: description of each group.
Let's look at the following code:

The code is as follows: Copy code
<Form id = "" class = "democss" action = "">
<Fieldset>
<Legend> Basic Register </legend>
<P> First name: <input type = "text" name = "fname" value = ""/> </p>
...
</Fieldset>
<Fieldset>
<Legend> Detailed Register </legend>
<P> Interest: <input type = "text" name = "interest" value = ""/> </p>
...
</Fieldset>
...
</Form>

Fieldset has borders by default, while legend is usually displayed in the upper left corner by default. However, in some pages, we do not want to make the default styles or la s of fieldset and legend affect the appearance of the design scheme. The solution is to set the border of fieldset to 0 in CSS and the display of legend to none.
◆ Label
Label labels should be familiar to everyone. We give a label to the text label in the form, and use the for attribute to associate it with the form component. The effect is to click the text label, the cursor is displayed in the corresponding form component.
Let's look at the following code:

The code is as follows: Copy code
<Form id = "wwwwebjxcom" class = "democss" action = "">
<Fieldset>
<Legend> Basic Register </legend>
<P>
<Label for = "fname"> First name: </label>
<Input type = "text" id = "fname" name = "fname" value = ""/>
</P>
...
</Fieldset>
<Fieldset>
<Legend> Detailed Register </legend>
<P>
<Label for = "interest"> Interest: </label>
<Input type = "text" id = "interest" name = "interest" value = ""/>
</P>
...
</Fieldset>
...
</Form>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.